I have 5 objects in my scene. Each of them have a box collider
(IsTrigger
selected) in front of them. I also have a menu in a GUITexture
. I want to show the menu if the box in front of the object is triggered and be able to rotate the object (that has the box just triggered). My problem is that if i assign the same GUITexture
to my objects, all of them are rotating if one is triggered.
If i print myGameObject.name
in the Start()
all 5 objects are printed at once.
Does anyone have an idea on how to fix this ?
The class that implements my idea is :
public class Trigger : MonoBehaviour {
public GameObject myGameObject ;
public GUITexture myGuiTexture;
private Vector3 rotation;
private Quaternion initialRotation;
private GameObject go;
void Start(){
myGuiTexture.enabled = false;
initialRotation = myGameObject.transform.rotation;
go = new GameObject("Details guiText");
go.AddComponent(typeof(GUIText));;
go.guiText.enabled = false;
}
void Update () {
if (myGuiTexture.enabled == true){
if (Input.GetKeyUp(KeyCode.Alpha1) || Input.GetKeyUp(KeyCode.Keypad1))
myGameObject.transform.rotation = initialRotation;
if (Input.GetKey(UnityEngine.KeyCode.Keypad1) || Input.GetKey(UnityEngine.KeyCode.Alpha1)){
rotation = new Vector3(0, Input.GetAxis("Mouse X"), 0);
myGameObject.transform.Rotate(rotation);
}
}
}
void OnTriggerEnter(){
myGuiTexture.enabled = true;
}
void OnTriggerExit(){
myGuiTexture.enabled = false;
}
}