Why UI isn't instantiate when I create a new object that has Canvas as a child component?
I have this object called Treant and I instantiated him from another Object called spawn. The spawn only instantiates a new Treant every second or not.
My problem is that the Treant has a Health bar but that same health bar isn't instantiated in the other Treant that I clone. The health bar will only appear in the next Treant the is created after I destroy the one that has the Health bar.
How can I made all Treants have the Health Bar on top of them?
This is my Spawn class:
public Component Enemies;
public Component Target;
private float lastSpawn = 5;
private float waited = 0f;
private int spawnPerWave = 1;
private int spawned = 0;
private List<int> fibonacci = new List<int>
{
1, 1
};
// Update is called once per frame
void Update()
{
CreateNewWave();
Spawn();
}
private void Spawn()
{
waited += Time.deltaTime;
if (lastSpawn < waited && spawned < spawnPerWave)
{
Debug.Log("Spawned");
waited = 0;
spawned += 1;
var enemy = Instantiate(Enemies);
enemy.GetComponent<EnemyAI>().target = Target;
}
}
private void CreateNewWave()
{
if(spawned == spawnPerWave && fibonacci.Count < 4)
{
spawned = 0;
spawnPerWave = fibonacci[fibonacci.Count - 1] + fibonacci[fibonacci.Count - 2];
fibonacci.Add(spawnPerWave);
}
}
Comment
Your answer
Follow this Question
Related Questions
Can someone help me? 0 Answers
Player cannot double jump 1 Answer
What are Unity3D's greatest strengths and weaknesses? 0 Answers
I want to click random position object 1 Answer
2D Collision Best Practice 0 Answers