So I’ve been getting 3 or 4 compiler errors when I attempt to run my game with the script attached. I’ve tried everything Unity’s error system tells me yet essentially I’m just going in scripting circles trying to follow and fix the errors that it gives me.
For example, one of it’s error messages were:
Assets/SampleAssets/Player_Health.js(43.9): BCE0044: expecting ), found ‘{’.
Nevertheless, here’s the script.
#pragma strict
public var currentHealth : float = 100.0;
public var maxHealth : float = 100.0;
public var minHealth : float = 0.0;
public var drainRate : float = 8.0;
public var hurtPlayer : boolean = false;
GUI.backgroundColor = Color.green;
function Update(){
if (currentHealth <= 0)
{
Application.Quit();
}
}
function OnControllerColliderHit(hit : ControllerColliderHit) {
if (hit.gameObject.tag == "z") {
currentHealth -= 25;
}
if(hit.gameObject.name == "healthPack"){
currentHealth += 15;
Destroy(hit.gameObject);
}
if(currentHealth >= maxHealth)
{
currentHealth = maxHealth;
}
if(currentHealth <= minHealth)
{
currentHealth = minHealth;
}
function(){
if(GUI.Button(Rect(10,10,currentHealth,23)
{
"Health: "+currentHealth.ToString;
}
}