for loop for game objects
I am making a for loop but it is not working and I get some errors so could you guide me on how to do this. I want the objects to be not active in the array I have. I did look at the Unity tutorials. Here is what I have so far.
public GameObject[] players
void Start ()
{
for(int i = 0; i < players.GetLength; i++)
{
players[i].gameObject.SetAtive = false
}
}
Answer by Tyche10 · May 12, 2016 at 08:49 AM
SetActive() is a method not a variable, so you need to talk to it differently. Players[i] is a gameobject already so no need to say players[i].gameObject. And you always need to add a semicolon at the end of a statement.
public GameObject[] players
void Start ()
{
for(int i = 0; i < players.GetLength; i++)
{
players[i].SetActive(false);
}
}
It was that simple I feel ashamed for asking a stupid question like this one
yea it is I am not very skilled with unity as I am only 17 and I have very little time to do this because of my exams that are cropping up soon. I want to learn so much more but I don't know where to look If I look at some tutorials made on udemay and some other websites and they are paid. so i am stuck. I want to learn how to make an FPS with AI but I have trying this for years but nothing has helped me. If you know anything then that would be great.
Your answer
![](https://koobas.hobune.stream/wayback/20220612080643im_/https://answers.unity.com/themes/thub/images/avi.jpg)