Scripts won't affect clones - Unity3d
- by user3666251
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.