I read almost all unity forum post on this topic one is about activating multiple at a time , others are in java script (have no clue how to convert ) and well i tought i could ask here well i want my wepons to be activated deactivated and i want to put them into aray because i would have lots of game object references
i have and aray of weapon game obects
public GameObject [] guns;
and i have my int
public int currentweaponprimary = 0;
public int currentweaponsecondary = 0;
and well since its in and aray i cant use smt like guns.Setactive(false or true) so how can i activate deactive them by those integers
public void ChangeWeapon(int weaponIndex) // weaponIndex is the index of weapon we need to activate
{
foreach (Transform weapon in weaponsHolderObject.transform) // weaponsHolderObject is GameObject which is parent of all weapons
{
if (weapon.GetSiblingIndex() == weaponIndex)
weapon.gameObject.SetActive(true); // if weaponIndex is the index of current child then we activate it
else weapon.gameObject.SetActive(false);// and deactivate every other weapons
}
}
ow dam sorry dint read your last post till the end wher you need to put currenweapontprimary in the () you help me a lot realy thank you and i think this post will help others to