I have a private boolean IsSelected on my prefab. The prefab is already in the scene.
On Start IsSelected is set to true, then on Fire1 it gets to false.
Fire1 also Instantiates another clone of my prefab.
I thought that it (the next clone) will automatically become selected, because IsSelected is true on Start.
It actually happen so, but…
But what also happens is that my PREVIOUS clone of the prefab, which got deselected after I pressed Fire1 ALSO gets selected. IsSelected also becomes true on him.
I thought the usage of private bool should’ve eliminated such problem?
What am I doing wrong?
That should not happen. There must be something else in your code.
using UnityEngine;
using System.Collections;
public class test : MonoBehaviour {
private bool mybool = false;
public GameObject myCube;
// Use this for initialization
void Start () {
mybool = true;
}
void OnMouseUp() {
mybool = false;
transform.Translate(1,0,0); // move out of the way for the new guy
Instantiate(myCube, new Vector3(0,0,0), Quaternion.identity);
}
}
This works perfectly. mybool on the first gameobject stays false while the new one is true due to its Start().
If you can’t figure it out, then post some code here.