I’ve searched the forums for a solution, but none that I found seem to apply or work for my situation. Anyways, I have two different gun objects, that are both parented to the Main Camera object under the FPS Controller form the Standard Assets. Both objects are placed in the scene where they would be if the player was carrying them, and both are active. I am trying to get them to deactivate when that current weapon is not selected, and then activate when it is selected. Attached to each each object is this script(with the necessary changes to the weapon variable and the tag, of course):
function Update(){
if (!(playerInit.playerWeapon == 1))
{
gameObject.active = false;
}
else
{
gameObject.active = true;
}
}
playerInit is a script attached to the player object. playerWeapon is a public static variable that is created and initialized in that script. This is the variable that controls the currently selected weapon(0 for pistol, 1 for smg). The code above is supposed to check if the variable is set to 1(value for the smg), and then activate/deactivate it based on this check. This script is attached to the smg object. There is a similar one attached to the handgun object, but the value is checked for 0. Both objects are set to active in the inspector. I am not sure why this is not working; from what I’ve read about the subject it should. The two gun objects are prefabs, if that matters. Can someone help me with this? I’d really appreciate it. Thanks for your time!!!