- Home /
Question by
OctopusSandwich · Apr 25, 2014 at 08:42 PM ·
colliderinputontriggerentergetbuttondown
Trying to make it so if I'm toucing something and have a button down it does something
I'm trying to make something happen when I am touching a tag and pressing a key but its not working.
void OnTriggerEnter(Collider other)
{
if (other.gameObject.tag == "House1" && Input.GetButtonDown("Interact")) {
Nothing happens when I try this, If I remove the Input.GetButtonDown it does let me enter it without pressing a button.
Comment
Best Answer
Answer by robertbu · Apr 25, 2014 at 09:02 PM
Your code above will only work if you happen to press the button down in the same frame that you entered the collider. Use GetButton() instead:
if (other.gameObject.tag == "House1" && Input.GetButton("Interact")) {
You would need to be pressing the button mapped to "Interact" as you crossed the trigger threshold; alternatively you could use OnTriggerStay.
Your answer
![](https://koobas.hobune.stream/wayback/20220613143605im_/https://answers.unity.com/themes/thub/images/avi.jpg)