good night someone can help me … is it possible to make an active between arrays?
I’m trying to create an active between arrays using int, but the maximum I got was only 1 array
public GameObject[] arrayObj;
void buttons(int num)
{
for(int i = 0; i < arrayObj.Length; i++)
{
if(arrayObj[num] == arrayObj[i])
{
arrayObj[i].SetActive(true);
}else {
arrayObj[i].SetActive(false);
}
}
}
Can you describe the Problem you are trying to solve? I’m not sure what ‘creating an active between arrays’ means. Describe the Setup, the Problem you have enountered, and what you want to see. I’m sure we can then quickly resolve the issue.
So friend, I’m trying to create a setactive between arrays, the script I created takes the int value set in void (int num) activates a certain object, for example, int 5 activates object 5 and so on.
but instead I wanted to use arrays.
arrayobj0 int 0, arrayobj1 int 1, arrayobj2 int 2;
would it be possible to do this?
If I understand you correctly, you want to store a number of game objects in an Array (or better a List) and then activate the object by index.
Yes, that is very much possible, and one of the main reaasons Arrays and Lists were invented
Let’s say you have an Array called ‘myObjects’ of GameObjects, and you want the fourth object to set active, The code for that could look like this
GameObject[] myGameObjects = ... / set up and fill the Array with objects
// now, set the fourth objct in the Array active
myGameObjects[3].SetActive(true); // NOTE: '3' because in Arrays we start with index 0 (Zero)
If you read any primer on Arrays, you’ll get the hang of this very quickly. My recommendation is you also immediately rad up on Lists, because they are a much better replacement for Arrays 99% of the time.
the idea would be like this but i need to do this 30 times this is horrible because i need 30 arrays so i wondered if i could store array in an int num and keep the loop activity
public GameObject[] Arrayobj1,Arrayobj2,Arrayobj3;
Public void ActiveArray1()
{
for(int x = 0; x < Arrayobj1.Length; x++)
Arrayobj1[x].SetActive(true);
Arrayobj2[x].SetActive(false);
Arrayobj3[x].SetActive(false);
}
Public void ActiveArray2()
{
for(int x = 0; x < Arrayobj2.Length; x++)
Arrayobj1[x].SetActive(false);
Arrayobj2[x].SetActive(true);
Arrayobj3[x].SetActive(false);
}
Public void ActiveArray3()
{
for(int x = 0; x < Arrayobj3.Length; x++)
Arrayobj1[x].SetActive(false);
Arrayobj2[x].SetActive(false);
Arrayobj3[x].SetActive(true);
}