I’m trying to make a code to toggle object visibility on/off using just one key. Right now I have to hit one key to turn things on another one to turn them off. I’ve got two chunks of script:
function Update () {
if (Input.GetKey ("joystick button 1")) {
gameObject.renderer.enabled = false;
}
if (Input.GetKey ("joystick button 2")) {
gameObject.renderer.enabled = true;
}
}
and…
Code:
var keyIsDown: boolean;
if (Input.GetKey("1")) {
if (!keyIsDown) {
keyIsDown = true;
gameObject.renderer.enabled = !gameObject.renderer.enabled;
}
} else {
keyIsDown = false;
}
I’ve tried different things to roll the boolean script into my game, but can’t figure out what I need to do to make it work. Any suggestions? Thanks.[/quote]