Okay I want it when a block collides with water, the player's score counter goes up by 1
I have a Gui Text object to start the Counter which just has
static var Counter = 0;
And on the water object I have a script to make the counter go up by 1 when it collides with a box that says
function OnCollisionEnter (other : Collision) {
if (other.gameObject.name == "smallcube")
Counter+=1;
}
But I'm still getting an error that says Unknown Identifier : 'Counter'
Can anyone tell me what's going wrong here?
To access a variable that you have made static you first have to declare in the script the variable is from. So it would be NameOfTheScriptCounterIsIn.Counter+=1;
To make it more clear, if the Counter is in a script named ScoreCounter it would be:
ScoreCounter.Counter+=1;
By the way, it's good to get into the habit of not capitalising the first letter of a variable.
system
March 7, 2011, 5:27am
3
I use this script:
var score = 0;
var scoreText = "Score: 0";
var mySkin : GUISkin;
function OnTriggerEnter( other : Collider ) {
Debug.Log("OnTriggerEnter() was called");
if (other.tag == "Asteroid") {
Debug.Log("Other object is a coin");
score += 25;
scoreText = "Damage%: " + score;
Debug.Log("Score is now " + score);
Destroy(other.gameObject);
GameObject.Find("Main Camera").animation.Play();
}
}
function OnGUI () {
GUI.skin = mySkin;
GUI.Label (Rect (100, 10, 500, 200), scoreText.ToString()); }
function Update(){
if( score == 100){
Application.LoadLevel(0);
}
}
it adds score to GUI skin when you collide with an object tagged Asteroid. Then when your score is 100 it returns to Level0.
-Hope this script will satisfy for your needs.