Question by
jaguilar0047 · May 04, 2018 at 04:49 PM ·
damagescore systemhealthbarkill playerhealth
Kill Count and Health Bar Scripts
Hello i am making a 3D game and am almost done!>O< BUT I can't seem to find a good tutorial on a UI kill counter script(each zombie killed = 1 point) or a UI health bar system script( when zombies come into contact with player/ or a certain Game Object health will go down) so if anyone could help it'd be greatly appreciated below are my scripts that i attempted but didn't work(i have no kill count code mostly focused on health bar) using UnityEngine; using System.Collections; using UnityEngine.UI;
public class HealthBar : MonoBehaviour { public Image currentHealthBar; public Text ratioText;
private float hitpoint = 150;
private float maxHitpoint = 150;
private void Start()
{
UpdateHealthbar();
}
private void UpdateHealthbar()
{
float ratio = hitpoint / maxHitpoint;
currentHealthBar.rectTransform.localScale = new Vector3(ratio, 1, 1);
ratioText.text = (ratio * 100).ToString() + '%';
}
private void TakeDamage(float damage)
{
hitpoint -= damage;
if (hitpoint < 0)
{
hitpoint = 0;
Debug.Log("Dead");
}
UpdateHealthbar();
}
private void HealDamage(float heal)
{
hitpoint += heal;
if (hitpoint > maxHitpoint)
hitpoint = maxHitpoint;
Debug.Log("Dead");
UpdateHealthbar();
}
}
using System.Collections; using UnityEngine;
public class Damage : MonoBehaviour { public bool isDamaging; public float damage = 10;
private void OnTriggerStay(Collider col)
{
if (col.tag == "Player")
col.SendMessage((isDamaging) ? "TakeDamage" : "HealDamage", Time.deltaTime * damage);
}
}
Comment