Input.GetKeyDown not reading? Am I being oblivious?
I'm having some trouble with my code right now. I've been stuck on this for the past few hours. The troubleshooting is fun and all but I just want to get to my next step. So here is the simplest form of code that I tested trying to get this to work.
using UnityEngine; using System.Collections;
public class ClearDebris : MonoBehaviour {
void OnTriggerEnter () {
Debug.Log("Entered Collider!");
//Works up till now
if (Input.GetKeyDown(KeyCode.Escape))
{
Debug.Log("E was Pressed!");
}
}
}
Essentially I want to press the E key while in a box collider to trigger an event such as Debug.Log("E was Pressed!"); but any way I try this it wont seem to cooperate. I have tried just GetKey instead of GetKeyDown and it still wont work. Is there a typo that I'm just oblivious to? Please Help!!!
Answer by kostasandre · Jul 19, 2016 at 01:31 PM
if (Input.GetKeyDown(KeyCode.E) well you have used escape.. :P
I realized that. That was just text to say that its working essentially. What it says in the Debug.Log means nothing in comparison to the key I press. Although after six hours of trying to figure out the solution I found it to be that I was using OnTriggerEnter rather than OnTriggerStay. A function I completely overlooked.
Your answer
Follow this Question
Related Questions
How do I use the capsule Collider? 1 Answer
Hey all I am working on a 3D maze game. I would like to know how i could start and end the levels . 1 Answer
How to deadtivate a gameobjects from the scene, if player has a character controller 0 Answers
Problems with touch input. 0 Answers
Moving relative to camera 0 Answers