Greetings
I have script which respawn player if he fall into water ( water object is plane ), this water object send damage to player health then player die and respawn to spawn point.
But sometime player does not respawn and he is keep falling then i need to restart the game.
these are the scripts
Player health:
public int maxHealth = 100;
public Transform spawnPoint;
public int health = 100;
private bool isDead;
void Start()
{
health = maxHealth;
}
void Update()
{
if(isDead)
{
Respawn();
}
}
public void TakeDamage(int amount)
{
health -= amount;
if (health <= 0)
Die();
}
void Die()
{
isDead = true;
}
void Respawn()
{
transform.position = spawnPoint.position;
health = maxHealth;
isDead = false;
}
Water:
public int damage = 100;
private void OnTriggerEnter(Collider other)
{
if (other.gameObject.CompareTag("Player"))
{
other.GetComponent<PlayerHealth>().TakeDamage(damage);
}
}
what is the problem ?!