- Home /
Question by
chrismisballs · Mar 03, 2011 at 02:28 AM ·
javascriptinput.getkey
making obgect invisble then visible
Ok so i have this
function Update () {
if (Input.GetKey ("c"))
renderer.enabled = false;
else if (Input.GetKey ("c"))
renderer.enabled = true;
}
What am i missing to make it so that once the button(c) is pressed the object goes invisible then when i press the button(c) again the object becomes visible again?
Comment
Best Answer
Answer by Mike 3 · Mar 03, 2011 at 02:40 AM
This will toggle it each time it's pressed:
function Update()
{
if (Input.GetKeyDown(KeyCode.C))
renderer.enabled = !renderer.enabled;
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613111055im_/https://answers.unity.com/themes/thub/images/avi.jpg)