Hi, I’m a total beginner to Unity and I just needed some help with scoring. At the moment what I’ve got is this:
var Counter : int = 0;
function Update () {
guiText.text = "Score: "+Counter;
Counter+=10;
}
Which updates the score constantly, but what I want is for the score to increase by 10 when there is a collision between two objects. Is there anyway I can specify this? Thanks in advance.
Update: Yay, I figured it out! Basically I wanted the score to increase whenever the basketball hit the target. This is the code I’ve now got attached to the score:
var Counter : int = 0;
function Update () {
guiText.text = "Score: "+Counter;
}
function React () {
Counter++;
}
And this code attached to the basketball:
function OnCollisionEnter(theCollision : Collision){
if(theCollision.gameObject.name == "Target"){
gameObject.Find("Score").SendMessage("React");
Debug.Log("Score!");
yield WaitForSeconds(1);
gameObject.active=false;
}
}
Thanks for the help!