Question by
AlexisDj18 · Mar 16, 2017 at 09:00 PM ·
unity 5scripting beginnerdamagehealth barhealth
I have a jump scare and I want it to affect my player's health when it activates it and kill my player when health = 0.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class Health : MonoBehaviour {
public float startHealth = 100;
public Image healthbar;
public GameObject player, boxME;
private float health;
// Use this for initialization
void Start () {
health = startHealth;
}
public void TakeDamage (float amount){
health -= amount;
healthbar.fillAmount = health / 100f;
if (health <= 0) {
player.transform.position = boxME.transform.position;
}
}
// Update is called once per frame
void Update () {
}
}
Comment
Your answer
Follow this Question
Related Questions
Interesting Script Problem 1 Answer
Health bar/damage script not working. Please help. 0 Answers
Health bar help 1 Answer
Rocket splash Damage 1 Answer