parsing error
void SwitchWeapon(int index) {
for (int i=0; i < nrWeapons; i++) {
if (i == index) {
//weapons[i].gameObject.SetActive(true);
weapons[i].gameObject.GetComponent ().enabled = true;
} else {
//weapons[i].gameObject.SetActive(false);
weapons[i].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.
so what does that mean......and yes there are 17 lines of code its just not showing it on that....at least on my there is
I mean, Line 17 is missing. You say the error happen on line 17, but there is only 12 lines of code pasted here. How would we know which one is Line 17?
Answer by Statement · Oct 25, 2015 at 10:44 PM
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[i].gameObject.GetComponent<RTCTankGunController> ().enabled = true;
else
weapons[i].gameObject.GetComponent<RTCTankGunController> ().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. :)
Your answer
Follow this Question
Related Questions
(31,16): error CS1525: Unexpected symbol `(', expecting `)', `,', `;', `[', or `=' 2 Answers
Resolution does not change when the DropdownMenu option is selected in build. 0 Answers
Negative Score 2 Answers
How do i fix this error? Cannot implicitly convert type `Sprite' to `UnityEngine.Sprite' 1 Answer