Question by
ZachAttack9280 · Oct 18, 2015 at 04:48 AM ·
weaponswitching
Weapon Switch
Hi, so for my game, i have two weapons or tools so far, a pickaxe and an axe, but i want to be able to change them by hiding one and showing one.
Here is my code:
#pragma strict
var axe : GameObject;
var pickaxe : GameObject;
private var visible : GameObject;
private var enabled : GameObject;
private var hide : GameObject;
axe.active = true;
pickaxe.active = false;
function Update () {
if (Input.GetKeyDown (KeyCode.Z))
{
hide = GameObject.Find("axe");
hide.GetComponent.<Renderer>().enabled = false;
}
if (Input.GetKeyDown (KeyCode.X))
{
hide = GameObject.Find("axe");
hide.GetComponent.<Renderer>().enabled = false;
}
}
But i get no error, and when i press the assigned key, the items don't switch or hide, what did i do wrong, i haven't found anything on the internet, but would you please give a good explanation and rewrite parts of the code? Thanks.
Comment
Your answer
Follow this Question
Related Questions
Store and access weapons from list C# 0 Answers
How can you do borderlands style random weapons and stat generation? 2 Answers
Landmine is spawning with wrong rotation 0 Answers
Having a few script errors that I ran into. 1 Answer
Weapon swap system is not working at all... is there a better way to do this 0 Answers