How to make GUI Text count up when an object collides with another?

I am new to Unity

This is my script so far:

function OnCollisionEnter (geraakt : Collision) {
 
     if(geraakt.collider.gameObject.tag == "Pickup"){
         GUI Text++; 
}
 
   UnityEngine.GUIText.text = "Collected: " + GUI Text; 
 
 }

**Any help/constructive criticism is gladly taken aboard :slight_smile: **

GUIText is an object, you cant increment (++) it.

GUIText.text is a string, even if you use it to display a number. I’m not sure if UnityScript lets you increment a string (making an automatic conversion), but you’ll be safer counting on a private integer variable and using that value later.

Also, I guess “UnityEngine.GUIText” is not a proper name for a variable, it’s a Class. You need an instance of GUIText.

function OnCollisionEnter (geraakt : Collision) {
    if(geraakt.collider.gameObject.tag == "Pickup"){
        counter++; //counter is a private integer defined on this script
    }
    myGuiText.text = "Collected: " + counter; //myGuiText is a GUIText reference defined on this script
}