Referring GameObjet's script from array

Hi.

I have a script called scr_WeaponController which stores all player’s weapons in an array. I use the following script to switch between the weapons:

void SwitchWeapon(int index)
    {
        for (int i = 0; i < weaponCount; i++)
        {
            if (i == index)
            {
                weapons*.gameObject.SetActive(true);*

}
else {
weapons*.gameObject.SetActive(false);*
}
}

}
Now each weapon object contains a script: “scr_weapon” with a function: “GetWeapon()” which sends all the information about said weapon (damage per shot, time between bullets, bullet spread etc.) forward to another script which does the shooting.
I’m trying to access the scr_Weapon script from the scr_WeaponController script like so:
void SwitchWeapon(int index)
{
for (int i = 0; i < weaponCount; i++)
{
if (i == index)
{
weapons*.gameObject.SetActive(true);*
weapons*.GetComponent<scr_weapon>.GetWeapon();
_}
else {_

_weapons.gameObject.SetActive(false);
}
}
}*

Now it seems like I can’t do it that way but I’m having a severe brain fart and can’t figure out why. All help is greatly appreciated.
Thanks!_

Your script is almost correct. You just have a syntax error at line 9.

Here is the correctet line:

weapons*.GetComponent<scr_weapon>().getWeapon();*

You missed the “()” :slight_smile:

Oh you got to be kidding me!!

Thanks Brullix3000! I was getting quite desperate with that :smiley: