Score updating after collision

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!

Make a Scorecounter script and attach this to your gui.Text object.


static var Counter : int = 0;

function Update () 
{    
    guiText.text = "Score: " + Counter;
}  

Make a scoretrigger script and attach this to the trigger that you want the ball to enter. Make sure that the checkbox 'isTrigger' on the gameobject is checked. Make sure that the object you're using as a ball is marked with a tag called ball (or if called something else, just change the CompareTag string to the tag's name).

function OnTriggerEnter(enterer : Collider) 
{
    if (enterer.collider.gameObject.CompareTag("ball"))
    {
        Debug.Log("Score!");
        Scorecounter.Counter ++;
    }
}

This is really usefull, thanks guys.

But how would I go about respawning my ball on collision?

Thanks,