- Home /
Question by
Dalecn · Aug 06, 2018 at 08:39 PM ·
c#collisionkeypresskeyboard input
Implementing collision and key pressing at once
I am trying to get my game so if you walk up to a sprite and stand next to it then press space you can talk to it. My code doesnt continuously check after a collision how would i get it to do so.
void OnTriggerEnter2D(Collider2D Talk)
{
if (Talk.gameObject.CompareTag("Player") && Input.GetKeyDown("space"))
{
Debug.Log("HI");
}
}
Comment
Best Answer
Answer by davidcox70 · Aug 06, 2018 at 09:58 PM
try changing your OnTriggerEnter2D to OnTriggerStay2D. This will continually fire when your player is within the trigger zone.
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Locations not registering as equal 1 Answer
Object reference not set to an instance of an object 2 Answers
Camera bounce back? 0 Answers