Does anybody have any idea why these “if” statements aren’t working? The objects “weaponSlot_1” and “weaponSlot_2” are assigned properly in the inspector, but the “if” statements still don’t work.
if (weaponSlot_1.activeInHierarchy == true)
{
SwitchActiveSlot(0);
Debug.Log("Loadout Slot Switched to 0");
}
if (weaponSlot_2.activeInHierarchy == true)
{
SwitchActiveSlot(1);
Debug.Log("Loadout Slot Switched to 1");
}
Any help at all would be deeply appreciated as I’m just stuck.
If any more information is needed I’m happy to share it.
Did you try adding debug.log calls to see what activeInHierarchy is showing? Did you add Debug.log calls to even make sure the method those if statements are in is being run?
Unfortunately showing if statements without context doesn’t help. Because at that point all we can say is the if statement isn’t working because the condition to satisfy that if statement isn’t true.
Debug.Log(weaponSlot_1.activeInHierarchy);
if(weaponSlot_1.activeInHierarchy == true)
{
//Do stuff if true.
}
Pretty simple. Now, if that Debug call doesn’t show in Unity’s Console, then your Update isn’t running. Which usually means the gameobject the script is on is off. So, make sure the gameobject this script is attached to isn’t off.
There’s also a debugger in your IDE that you can attach, set breakpoints, then step over the code line by line as it executes, at the same time you can view the values of all variables. Consider how quickly that’ll explain the code’s behaviour, and then you’ll want to figure out how that works (don’t ask: there’s tons of tutorials available ).