Parsing error (151628)

void SwitchWeapon(int index) {

      for (int i=0; i < nrWeapons; i++)    {
          if (i == index) {
              //weapons*.gameObject.SetActive(true);*

weapons*.gameObject.GetComponent ().enabled = true;*
} else {
//weapons*.gameObject.SetActive(false);*
weapons*.gameObject.GetComponent ().enabled = false;*
}
}
}
not sure why I am getting this error plz help at 17,9

Your code was not formatted so any generics will have been stripped out. Also there aren't 17 lines of code. Please include the full error message and tell us which of the lines that you paste get the error.

1 Answer

1

nrWeapons isn’t defined.

weapons isn’t defined.

Your script must define those variables. I think it’s safe to eliminate nrWeapons and use weapons.Length instead. I don’t know what type the weapons array is meant to be.

using UnityEngine; 
using System.Collections;

public class Weaponchanging : MonoBehaviour 
{
    public Component[] weapons; // WARNING! I don't know what type you expect!

    void SwitchWeapon(int index) 
    {         
         for (int i=0; i < weapons.Length; i++)  // Using weapons.Length instead of other var.  
         {
             if (i == index)
                 weapons*.gameObject.GetComponent<RTCTankGunController> ().enabled = true;*

else
weapons*.gameObject.GetComponent ().enabled = false;*
}
}
} // Added missing bracket

ok I will try it.....the weapons are missile and mk 45 5 inch deck gun on a destroyer

thank you very much for all the help I very glad that you helped me and hope to help you some time in the future. :)