parsing error
I have this script but I got a parsing error and don't know what to do about it......XD I know little to nothing about codes so I am asking you.
this is the code I need help with
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; } } }
Answer by Landern · Oct 26, 2015 at 01:42 PM
enabled is not a member of the Component type. When you use just GetComponent(or GetComponent and a string as a type) you get back a Component type instead of something more specific. The code you included in your comment isn't specific enough as to what component you're trying to interact with that also has a member called enabled. The enabled member is typically gained by the Behavior class.
Anyways, your code below, you should include the script you're trying to disable it will typically be done through generics(whats between angle brackets). <-- Please click the link and read about them
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; // ? What are you trying to enable?
}
else
{
//weapons[i].gameObject.SetActive(false);
weapons[i].gameObject.GetComponent().enabled = false; // ? What are you trying to disable?
}
}
}
You can also see this is not the first time this question has come up: example
Your answer
Follow this Question
Related Questions
Menu object not responding 0 Answers
Wrong after Update? 0 Answers
GameObject changes to None in inspector after pressing Play 0 Answers
AQUAS : NullReferenceException: Object reference not set to an instance of an object 0 Answers
Error CS8025: Parsing Error 3 Answers