Hi! I am kind of new to Unity.
So, I've been trying to destroy set of clones on mouse click instantiated during my game play.
My code for instantiation goes like this.
public class inst : MonoBehaviour {
public GameObject ch;
public Transform[] spawnpoint=new Transform[3]; // Use this for initialization
void Start () {
spwn();
}
void spwn(){
for (int i=0; i<4; i++) {
Vector3 spawnVector = new Vector3 (spawnpoint[i].position.x, spawnpoint[i].position.y, spawnpoint[i].position.z);
Instantiate (ch , spawnVector, spawnpoint[i].rotation);
}
}
// Update is called once per frame
void Update () {
}
}
And, I have a separate code for destroying the clones on Mouse click which is added to the respective prefab.
But when I am trying to destroy them, they are getting destroyed in the same order in which they
are created.
For eg., if I am clicking on my clone in spawnpoint[2] transform, spawnpoint[0] clone is getting destroyed. And on a second click of the same spawnpoint[1[]'s transform is being destroyed.
Please help me in making my code work properly. Thanks in advance :)
p.s.: I might have misunderstood and would have something wrong. I am just a beginner. In that case please correct me.
↧