- Home /
Input getkey, keyup and keydown not working?!
Hello,
I am having trouble with the Input.GetKey
commands, Input.GetAxis
works fine. Also the Input.GetKey(Keycode./* all combinations*/)
doesn't work.
My Code:
function OnTriggerEnter( col : Collider){
nameText.SetActive(true);
if(col.gameObject.tag== "Player"){
Debug.Log("In trigger");
if(Input.GetMouseButton(0)&& !showLoot){
Debug.Log("In trigger and clicked");
animation.Play("open");
yield WaitForSeconds(2);
showLoot =true;
_showLoot = showLoot;
PlayerInventory.isViewingOther = true;
PlayerInventory.inventory = true;
}
}
}
hope you can help me :)
ahh very clever! :) thank you very much. the perfect answer :)
I converted the comment to an answer so that you can accept it to mark the question as solved.
Answer by ExTheSea · May 13, 2013 at 05:56 PM
ButtonDown and Up -Events are only true for one frame. That's why they are normally in Update() or OnGUI() functions. Think about it. Your onTriggerEnter function gets called in one frame. The key has to be pressed/released at this exact frame to get it to work. I would recommend you to put the Input stuff in Update or OnGUI and use booleans instead to get what you want to.