- Home /
Question by
smiley-HD · Nov 02, 2014 at 11:10 PM ·
javascriptgetkeydownswap
swap between two items
hi i am working on a game where you scan switching between two objects you hold in your hand (shortl) and (loongl) and you should be able to switch between them by pressing the "F" (that's two flashlights just so you know) I've created a script which changes from (shortl) by pressing the "F" but I can not change back again any ideas?
#pragma strict
var shortl : GameObject;
var loongl : GameObject;
shortl.active = true;
loongl.active = false;
function Update () {
if (Input.GetKeyDown ("f"))
{
shortl.active = false;
loongl.active = true;
}
}
Comment
Best Answer
Answer by Kiwasi · Nov 02, 2014 at 11:12 PM
The typical way to do this is
if (Input.GetKeyDown ("f"))
{
shortl.active = !shortl.active;
loongl.active = !loong1.active ;
}