I want it where if I stand in the trigger than my health will go down slowly, but I don’t know how to make it go slowly. I used a int value to make it a little slower which didn’t really slow it down much, so I tried a float value, but it says that I cannot use a float value. Somebody help. Heres my code. It’s line 52 where I’m having the problem.
using UnityEngine;
using System.Collections;
public class Soldier : MonoBehaviour {
public int health = 100;
public int hitSpeed = 1;
public GUIText healthText;
public GUIText dead;
public bool canPickUpHealth;
public bool isHit = false;
public bool isDead = false;
// Use this for initialization
void Start () {
SetHealthText();
dead.text = "";
canPickUpHealth = false;
isDead = false;
}
// Update is called once per frame
void Update () {
if(health >= 100)
{
health = 100;
SetHealthText();
}
if(health < 0)
{
health = 0;
SetHealthText();
}
if(health <= 0)
{
Time.timeScale = 0;
dead.text = "YOU ARE DEAD";
SetHealthText();
}
if(health == 100)
{
canPickUpHealth = false;
}
else
{
canPickUpHealth = true;
}
if(isHit)
{
health -= 15 * hitSpeed;
SetHealthText();
}
else
{
isHit = false;
}
}
void OnTriggerEnter(Collider other)
{
if(canPickUpHealth)
{
if(other.gameObject.tag == "Health" && health <= 100)
{
other.gameObject.SetActive(false);
health = health + 15;
SetHealthText();
}
}
if(other.gameObject.tag == "Enemy" && health > 0)
{
isHit = true;
}
}
void OnTriggerStay(Collider other)
{
if(other.gameObject.tag == "Enemy")
{
isHit = false;
}
}
void OnTriggerExit(Collider other)
{
if(other.gameObject.tag == "Enemy")
{
isHit = false;
}
}
void SetHealthText()
{
healthText.text = "Health: " + health.ToString();
if(health <= 0)
{
dead.text = "YOU ARE DEAD";
}
}
}