mlager8
01-25-2011, 07:26 PM
I know this is not really the proper place but seeing as there is no general scripting on unity forum, I figure the fine gents over here may be able to help me out. Tried the unity forum but I'm not getting much help. Anyway here is whats going on;
I'm trying to make a small script to switch weapons (they're actually bottles of cleaning agent... dont ask) in my FPS. I'm using the SetActiveRecursive command to make the different "weapons" appear. The code I'm using is simple so I thought it wouldn't really give me any problems, but that assumption was dead wrong. Currently The first weapon works great, (shuts on and off when I switch keys) the rest dont work at all and the last weapon is constantly in an on state and wont shut off even though I have the active box unchecked, as soon as the game starts it checks it's self on. Here is the code so far, if anyone could help I would be very appreciative!
var HFS : GameObject;
var HMS : GameObject;
var HAP : GameObject;
var HPO : GameObject;
function Update () {
if (Input.GetKey(KeyCode.Alpha1))
HFS.SetActiveRecursively(true);
HMS.SetActiveRecursively(false);
HAP.SetActiveRecursively(false);
HPO.SetActiveRecursively(false);
if (Input.GetKey(KeyCode.Alpha2))
HFS.SetActiveRecursively(false);
HMS.SetActiveRecursively(true);
HAP.SetActiveRecursively(false);
HPO.SetActiveRecursively(false);
if (Input.GetKey(KeyCode.Alpha3))
HFS.SetActiveRecursively(false);
HMS.SetActiveRecursively(false);
HAP.SetActiveRecursively(true);
HPO.SetActiveRecursively(false);
if (Input.GetKey(KeyCode.Alpha4))
HFS.SetActiveRecursively(false);
HMS.SetActiveRecursively(false);
HAP.SetActiveRecursively(false);
HPO.SetActiveRecursively(true);
}
I'm trying to make a small script to switch weapons (they're actually bottles of cleaning agent... dont ask) in my FPS. I'm using the SetActiveRecursive command to make the different "weapons" appear. The code I'm using is simple so I thought it wouldn't really give me any problems, but that assumption was dead wrong. Currently The first weapon works great, (shuts on and off when I switch keys) the rest dont work at all and the last weapon is constantly in an on state and wont shut off even though I have the active box unchecked, as soon as the game starts it checks it's self on. Here is the code so far, if anyone could help I would be very appreciative!
var HFS : GameObject;
var HMS : GameObject;
var HAP : GameObject;
var HPO : GameObject;
function Update () {
if (Input.GetKey(KeyCode.Alpha1))
HFS.SetActiveRecursively(true);
HMS.SetActiveRecursively(false);
HAP.SetActiveRecursively(false);
HPO.SetActiveRecursively(false);
if (Input.GetKey(KeyCode.Alpha2))
HFS.SetActiveRecursively(false);
HMS.SetActiveRecursively(true);
HAP.SetActiveRecursively(false);
HPO.SetActiveRecursively(false);
if (Input.GetKey(KeyCode.Alpha3))
HFS.SetActiveRecursively(false);
HMS.SetActiveRecursively(false);
HAP.SetActiveRecursively(true);
HPO.SetActiveRecursively(false);
if (Input.GetKey(KeyCode.Alpha4))
HFS.SetActiveRecursively(false);
HMS.SetActiveRecursively(false);
HAP.SetActiveRecursively(false);
HPO.SetActiveRecursively(true);
}
