Question by
$$anonymous$$ · Feb 27, 2019 at 10:09 PM ·
health-deduction
why doesn't my health script work?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerHealth : MonoBehaviour
{
public int currentHealthPlayer = 1500;
[SerializeField] GameObject deathFX;
[SerializeField] Transform parent;
void Update()
{
// if the player is dead destroy him
if (currentHealthPlayer <= 0)
Destroy(gameObject);
// if curHelath < 0 -> curHealth = 0; if currentHealthPlayer > 1500 -> currentHealthPlayer = 1500
currentHealthPlayer = Mathf.Clamp(currentHealthPlayer, 0, 1500);
}
public void ApplyDamage(int damageToTake)
{
Debug.Log(Time.frameCount + ": ApplyDamage was called.");
currentHealthPlayer -= damageToTake;
GameObject fx = Instantiate(deathFX, transform.position, Quaternion.identity);
fx.transform.parent = parent;
}
}
Comment
Your answer

Follow this Question
Related Questions
Health bar help 1 Answer
Unity javaScript player taking damage from enemy 0 Answers
Damage not working properly 1 Answer
Health system in a text based game. 2 Answers
Display Hit Text On Collition 0 Answers