I am fairly new to scripting.
var Health : float = 100.0;
var Hunger : float = 100.0;
function Start () {
}
function Update () {
Hunger -= Time.deltaTime/4;
if(Hunger <= 5){
Health --;
}
if(Health <= 0){
print ("You Died");
}
Health = Mathf.Clamp(Health, 0.0, 100.0);
Hunger = Mathf.Clamp(Hunger, 0.0, 100.0);
}
function OnTriggerEnter (other : Collider) {
if(other.GameObject.name == ("CoconutCol") && Hunger <= 90.0 ){
Hunger ++ 10;
Destroy (other.GameObject.transform.parent.GameObject);
}
}
For future question, please 1) describe what the script is designed to do, 2) indicate what problems it is having, and 3) include a copy of any error messages if it is a compile time error.
You have two kinds of errors here. First on line 30, the line should be:
Hunger += 10;
Second ‘GameObject’ is the class. ‘gameObject’ with a small ‘g’ is the specific instance. So here is the script that will compile:
#pragma strict
var Health : float = 100.0;
var Hunger : float = 100.0;
function Start () {
}
function Update () {
Hunger -= Time.deltaTime/4;
if(Hunger <= 5){
Health--;
}
if(Health <= 0){
print ("You Died");
}
Health = Mathf.Clamp(Health, 0.0, 100.0);
Hunger = Mathf.Clamp(Hunger, 0.0, 100.0);
}
function OnTriggerEnter (other : Collider) {
if(other.gameObject.name == ("CoconutCol") && Hunger <= 90.0 ){
Hunger += 10;
Destroy (other.transform.parent.gameObject);
}
}