- Home /
This question was
closed Nov 02, 2014 at 05:16 PM by
robertbu for the following reason:
Duplicate Question
Question by
The_Unity_Game_Developer · Nov 02, 2014 at 05:16 PM ·
gui.labelhealth
GUI.Label error.
Hello one and all!
I have started again with my enemy AI and Health script.
I'm trying to use GUI's (such as GUI.Label) to create a visual enemy health, however I always get the error of:
Assets/EnemyAI.js(41,26): BCE0023: No appropriate version of 'UnityEngine.GUI.Label' for the argument list '(UnityEngine.Rect, System.Type)' was found.
I was wondering why this is happening?
Here is my script:
var health = 10;
var TakeDamage : boolean = false;
var fullhealth = Texture;
function OnTriggerEnter(other : Collider)
{
if(other.tag == "Player")
{
TakeDamage = true;
}
}
function OnTriggerExit(other : Collider)
{
if(other.tag == "Player")
{
TakeDamage = false;
}
}
function Update()
{
if(TakeDamage)
{
if(Input.GetButtonDown("Fire1"))
{
health -= 1;
}
}
if(health <= 0)
{
health = 0;
Destroy(gameObject);
Debug.Log("Enemy is dead!");
}
}
function OnGUI () {
if(health >= 10)
{
GUI.Label(Rect(10,40,100,100),fullhealth);
}
}
So basically if the health is equal to or more than 10, it will display the fullhealth texture.
Thanks in advance!
Comment
Answer by robertbu · Nov 02, 2014 at 05:17 PM
Line 3 should be:
var fullhealth : Texture;
...with a ':' not an '='.
Thanks! Just a simple error after 3 hours of sleep I guess. Hehe!