Hello there. I’ve got some troubles with my respawn script. I’ve read a lot about respawning scripts but haven’t found what would be the best for my video game :<
I think that almost everything is ok in this script, except when i use “Debug.Log(“message”);”, I figure out that this part of the script is not executed. Could someone help me ? Thanks !
public float maxHealth = 1000f;
public float curHealth = 0f;
private bool isAlive = true;
private float timer;
private int waitingTime = 2;
public GameObject enemyPrefab;
private GameObject spawnPos;
private StatsMage statsMage;
void Start () {
curHealth = maxHealth;
statsMage = Character.GetComponent<StatsMage>();
enemyPrefab = GameObject.Find("ennemy");
spawnPos = GameObject.Find("spawnPos");
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Weapon")
{
curHealth -= statsMage.DamageDealMage;
}
}
void Update () {
if (curHealth <= 0)
{
isAlive = false;
Destroy(enemyPrefab);
}
if (isAlive == false)
{
timer += Time.deltaTime;
if (timer > waitingTime)
{
Debug.Log("Message");
Instantiate(enemyPrefab,spawnPos.transform);
isAlive = true;
timer = 0;
}
}
}