I have a script that spawns a certain object (boss) if a object with a certain tag dies. Everything works completly fine, but only the “BossRanged” gets instantiated twice, the other ones only once, but why?
The script is only attached to the “boss objects” and they get destroyed after going under 0 health (see in code).
My code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class BossStats : MonoBehaviour
{
public GameObject BossTank;
public GameObject BossRanged;
public GameObject BossSeed;
public float health = 2500f;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
}
public void TakeDamage(float amount)
{
health -= amount;
if (health <= 0f)
{
Die();
}
void Die()
{
if (this.tag == "CasterBoss" && health <= 0)
{
Instantiate(BossTank, this.transform.position, this.transform.rotation);
Destroy(this.gameObject);
}
if (gameObject != null && this.tag == "TankBoss" && health <= 0)
{
Instantiate(BossRanged, this.transform.position, this.transform.rotation);
Destroy(this.gameObject);
}
if (gameObject != null && this.tag == "RangedBoss" && health <= 0)
{
Instantiate(BossSeed, this.transform.position, this.transform.rotation);
Destroy(this.gameObject);
}
if (gameObject != null && this.tag == "SeedBoss" && health <= 0)
{
Destroy(this.gameObject);
}
}
}
}
It worked! Thank you very much! ^^
– renren30