Scripts won't affect clones - Unity3d

Posted by user3666251 on Game Development See other posts from Game Development or by user3666251
Published on 2014-06-12T18:25:29Z Indexed on 2014/06/12 21:41 UTC
Read the original article Hit count: 387

Filed under:
|
|

I made a script which swaps two game objects on click.But the script won't work because the objects are actualy clones of the original prefab.

This is the script (UnityScript):

#pragma strict

var object1 : GameObject;
var object2 : GameObject;
function OnMouseDown ()
{

Instantiate(object2,object1.transform.position,object1.transform.rotation);

Destroy(object1);
}

I use this script to create other game objects (clones)[c#] :

using UnityEngine;
using System.Collections;

public class Spawner : MonoBehaviour {

public GameObject[] obj;
public float spawnMin = 1f;
public float spawnMax = 2f;


// Use this for initialization
void Start () {
    Spawn ();
}

void Spawn() 
{
    Instantiate(obj[Random.Range(0, obj.GetLength(0))],transform.position, Quaternion.identity);
                    Invoke ("Spawn", Random.Range (spawnMin, spawnMax));
                    }

}

The objects get renamed to NAME (Clone).

What I wanna do is make the script affect clones too.So they will swap when I click on them.

© Game Development or respective owner

Related posts about c#

Related posts about unity