Hi everyone,
I’m new to unity (and javascript ^^) and I can’t find a solution to my problem.
Here is the problem: I have a script which is working, but when I want to add interactivity with Input.GetButton, nothing happens.
Here is my script:
function OnTriggerEnter(myTrigger : Collider) {
Debug.Log("Hi");
if(myTrigger.gameObject.name == "Sphere" && Input.GetButtonUp("Retreat")){
Debug.Log("follow");
gameObject.GetComponent( IA_Follow_Player ).enabled = true;
}
}
function OnTriggerExit(myTrigger : Collider) {
if(myTrigger.gameObject.name == "Sphere"){
gameObject.GetComponent( IA_Follow_Player ).enabled = false;
Debug.Log("Stun");
}
}
Without " && Input.GetButtonUp(“Retreat”) " (first if statement), everything is working perfectely. But when I add it, I don’t have any error on the console and I can read the messages “Hi” and “Stun” from the console. Unfortunately, I can’t read “Follow” and my script “IA_Follow_Player” doesn’t play.
Basically, I just want my script “IA_Follow_Player” to execute if the gameObject my script is attached to is colliding with “Sphere” AND if I press a key.
(I also tried with Input.GetButton(“Retreat”) / Input.GetButtonDown(“Retreat”) / Input.GetKey(1) / Input.GetKeyUp(1) / Input.GetKeyDown(1), and I named in the input manager a “Retreat” input. I also tried many keys to be sure that it was not from my keyboard).
Does anyone have a clue ?
Thanks a lot.