Hi everyone
I did this script for my character gets damage when he is touched by enemy(Zombie) but his Health
does not decrease in this case could u help me?
I´m learning how to programm and i´m really novice so…
Here is my code
Sorry i do not know how to add the code like u , getting color and that kind stuff
using UnityEngine;
using System.Collections;
public class HealthGaby : MonoBehaviour
{
public float health = 100;
public const float maxHealth = 100;
public Texture2D gabyH = null;
public float modifySize = 0.86f;
public Rect postion = new Rect(5, 5, 100, 25);
private void Start()
{
health = maxHealth;
}
private void Update()
{
if (health < 0)
{
health = 0;
}
else if (health > maxHealth)
{
health = maxHealth;
}
}
private void OnGUI()
{
if (gabyH != null)
{
postion.width = health*modifySize;
GUI.DrawTexture(postion, gabyH);
}
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == “Enemy”)
{
DamagePlayer(5);
Destroy(col.other);
}
}
public void DamagePlayer(float damage)
{
health -= damage;
}
}