Collision bug

Hello! So I tested this code wich is supposed to disable/enable collisions

if (Input.GetKey(KeyCode.C))
{

        collisionDisabled = !collisionDisabled;

    }

but the problem is that it is in the update section so it updates every second and it is impossible to press the key c just enough to enable/disable it. Is there any fix I could try like addid a wait command or something?

use Input.GetKeyDown(KeyCode.C) instead.

Input.GetKey(KeyCode.C) checks if a key is currently down and as you have mentioned, the Update function is just too fast. Input.GetKeyDown(KeyCode.C) only checks if the key was pressed in this frame. On the next frame, it will not be true, even if the key is still being held down

1 Like

Thank you very much!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms