- Home /
Won't Enter GetButton Statement
Well I have a simple game with a player walking around and I have a broomstick for the player to mount. Problem is, that I just cant get the code to enter an if() { statement. My code is here:
var player1 : Transform; var player2 : Transform; var seat : Transform;
function OnTriggerEnter(other : Collider) { if (other.tag == "Player1") { Debug.Log("P1 in"); if(Input.GetButton("Mount1")) { Debug.Log("P1 press"); player1.position = seat.position; } } if (other.tag == "Player2") { if(Input.GetButton("Mount2")) { player1.position = seat.position; } } }
It all works fine until i get to the button press. The input Mount1 is set to the key / and has all the proper setting as far as I can see.
Have you tried using Get$$anonymous$$ey ins$$anonymous$$d? Just to check if you've not set get button correctly. Does GetButton work in a plain function Update() ?
$$anonymous$$ake sure that it is in fact OnTriggerEnter you want, and not OnTriggerStay.
Woah oops lol dont copy/paste because i forgot to change the player 2 part to put player 2 in the seat ;)
Answer by qJake · Jul 11, 2010 at 11:37 PM
I see two problems.
First, you probably want OnTriggerStay, not OnTriggerEnter, since you're catching input values, and secondly, you probably want GetButtonDown, not GetButton, unless you want the code inside the GetButton call to repeat every frame.