mr.killmeplease
Explore posts from serversWhy isnt my player being deleted and the scene changed?
im not sure what a breakpoint is but i figured out that its something with the reduction of health because the attack successful debug worked. But for some reason instead of killing the player after getting hit 10 times, it just continued running.
14 replies
Why isnt my player being deleted and the scene changed?
and then the player health script:
using UnityEngine;
using UnityEngine.SceneManagement;
public class PlayerHealth : MonoBehaviour
{
public int maxHealth = 100;
public int currentHealth;
void Start()
{
currentHealth = maxHealth;
}
}
14 replies
Why isnt my player being deleted and the scene changed?
{
// Reduce player's health
Debug.Log("Attack successful!");
PlayerHealth playerHealth = player.GetComponent<PlayerHealth>();
if (playerHealth != null)
{
playerHealth.currentHealth -= damage; // Reduce player's health
if (playerHealth.currentHealth <= 0)
{
Destroy(gameObject);
SceneManager.LoadScene("Main Menu");
playerHealth.maxHealth = 100;
}
}
}
}
}
14 replies