I have script for cube, it is a list of game objects which I need to set inactive. When I start the program, nothing happens but it should to make inactive some of game objects. But when I stop the program, the script suddenly works for some reason. What could be the reason of this strange bug?
If you're lazy: script for game objects works only after stopping program, but should when program is working.
Code:
using UnityEngine;
public class BlockController : MonoBehaviour
{
public GameObject[] obje = new GameObject[2];
void Start()
{
for(int x = 0; x < obje.Length; ++x)
{
obje[x].SetActive(false);
}
}
}
Asked a bot that on some forums, asked AI, tried to fix by myself, but nothing happens
Probably, you didn't link your gameobjects to the BlockController
script on the scene. Check if you have errors in the console log.
Also, you don't have to initialize the array with new GameObject[2];
and set its size explicitly, this will be done by Editor.
public class BlockController : MonoBehaviour
{
public GameObject[] objects;
void Start()
{
foreach (GameObject next in objects)
next.SetActive(false);
}
}