Question by
ParadoxOfficial · Mar 14, 2018 at 05:45 PM ·
c#inputkeycodebooleansinput.getkey
Using one key only, change bool to true or false depending on it's current value
I want my boolean value to switch to true if currently false, or switch to false if currently true using only one Keycode. Here is my C# code: bool cameraCollisionEnabled = true; void Update () { if (Input.GetKey (KeyCode.C)) { cameraCollisionEnabled =! cameraCollisionEnabled; Debug.Log ("Camera Collision Status Updated"); } }
Comment
Answer by Lilius · Mar 14, 2018 at 07:04 PM
I think this:
cameraCollisionEnabled =! cameraCollisionEnabled
Should be;
cameraCollisionEnabled = !cameraCollisionEnabled
Answer by ParadoxOfficial · Mar 14, 2018 at 11:20 PM
Thank you but this still doesn't fix the problem. I fixed it by changing Input.GetKey to Input. GetKeyDown so that it can only change once each time I press C.