- Home /
input.getkeydown dialouge system help
So I'm trying to make a basic dialogue system using on-trigger-enter and i want my character to enter the trigger area and press "f" however when i go in the trigger and press "f" I'm not getting the console message for but i am for when i enter the trigger. After some research it said that the input.getkeydown has to be in the update function but the problem is that even when I'm not in the trigger i can still press f and the console message will appear. How do I make it i can only press f in the trigger
function Update ()
{
if (Input.GetKeyDown("f"))
{
Debug.Log("f is pressed");
}
}
function OnTriggerEnter (other : Collider)
{
if(other.tag == "Player")
{
Debug.Log("Press F to Talk");
}
}
Answer by Suddoha · Sep 09, 2015 at 06:57 PM
The Update function cannot know whether you're in a trigger or not. You need a flag, i.e. a boolean, that will be set to true as soon as you enter the trigger and set to false as soon as you exit the trigger (OnTriggerExit). Then, in the Update method, do not only check for the Input to happen, but also for the boolean variable to be true.
if(Input.GetKeyDown("f") && myBooleanVariable)
{
// your logic
}
Your answer

Follow this Question
Related Questions
Platform OnTriggerEnter movement with User Input 0 Answers
OnTriggerEnter behaving oddly?!? 1 Answer
Becoming parent after OnTriggerStay/Enter? 1 Answer
Won't Enter GetButton Statement 1 Answer
How do I make my platform not be jerky? 2 Answers