- Home /
Question by
valtteri_m · Jan 17, 2015 at 01:26 PM ·
javascriptrendererfindhidegetkey
Hide object on key if finds object
Hi im having some problems with my script, id like it so that when I press the left or right arrow key, it would search for "MeleeWeapon(Clone)" and then if it finds that object while pressing the the left or right key it would disable the players renderer.
my script:
var player: GameObject;
private var MeleeWeapon : GameObject;
function Update(){
if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)){
if(GameObject.Find("MeleeWeapon(Clone)")){
var MeleeWeapon = Player.Find("MeleeWeapon(Clone)").gameObject;
player.renderer.enabled = false;
}else{
player.renderer.enabled = true;
}
}
}
Comment