Component Image disabled after a spawn
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);
}
}
}
Of course at runtime, after a short amount of time i get a very low frame rate and these errors because of the name of clones.
Answer by pictoo · Sep 08, 2016 at 12:03 PM
Finally got it... sorry square.enabled = true; square.name = "light"; By the way, Any idea to do that in another method ?
Your answer
Follow this Question
Related Questions
problem with instantiated clones not running OnEnterTrigger / OnexitTrigger script? 0 Answers
Event.KeyCode not detecting mouse click 0 Answers
Button inside a window not responding! 1 Answer
i am having problems while building to ps4 0 Answers
Canvas Scaler is not applied to the dynamically added canvas text 2 Answers