Hello,
I’m trying to buid animated panels on UI.
The method i’ve choosen maybe is not the best one ( and not the best optimized too )
The two screen shots will explain better than i can do with words what is the problem.
I spawn images, then destroy them and respawn again.
But as you can see on the second screenshot, the image component is disabled when it comes to the second spawn. And I can’t find what i’m doing wrong in the code.
Thanks in advance for any help.
Here is my code.
private void Start ()
{
SpawnLights();
}
private void Update ()
{
if (Time.time > nextSpawnTime )
{
nextSpawnTime += period;
DestroyLights();
SpawnLights();
}
}
private void SpawnLights ()
{
for (int i = 0; i < spawnCount; i++)
{
column++;
if (column > panelSizeX)
{
column = 1;
raw++;
}
offset = new Vector3 ((cellSize / 2) * column + (cellSize / 2) * (column - 1), (cellSize / 2) * raw + (cellSize / 2) * (raw - 1), 0);
if (Random.value >= 0.5)
{
spawn = true;
} else
{
spawn = false;
}
if (spawn)
{
square = Instantiate (square, panelContainer.transform.position + offset, panelContainer.transform.rotation) as Image;
square.transform.SetParent (panelContainer.transform, true);
}
}
}
private void DestroyLights ()
{
foreach (Transform child in panelContainer)
{
column = 0;
raw = 1;
GameObject.Destroy(child.gameObject);
}
}
}