Collecting Papers and Keeping Track of how many collected - need help

Hi, having many issues. This is my code… the furthest I’ve gotten after a half day trying to get it to work. I have 30 papers scattered around my scene and I want the papers to be destroyed/vanish when the first person controller touches them and I’d like the ‘score’ to count the number collected - so far this code is only able to display the GUI as 0 Papers - which is great, but I really need help on this.

var papersDisplay : GUIText;

var paper = 0;

var paperToWin = 30;

function Start() {

DisplayAmount();

}

function DisplayAmount () {

papersDisplay.text = ""+ paper + " Papers";

}

function OnTriggerEnter( other : Collider ) {

if (other.tag == "paper") {

    paper += 1;

    Destroy(other.gameObject);
}

}

A few things to check :

  • the statement [other.tag == “paper”] should read [other.gameObject.tag == “paper”]

  • does the gameObject have the tag “paper”

  • does either the player or the paper have a rigidbody component? e.g. Note that trigger events are only sent if one of the colliders also has a rigidbody attached.

  • is either of the object’s collider’s set to [is Trigger]

From the Unity Scripting Reference : http://unity3d.com/support/documentation/ScriptReference/Collider.OnTriggerEnter.html

  • Edit with code from comments :

     var Paper : int = 0;
     var paperToWin : int = 30;
    
     function Start() {
     } 
    
     function Update() { 
     } 
    
     function OnTriggerEnter( other : Collider ) {
     	// Debug.Log("Triggered by [tag] : " + other.gameObject.tag);
     	// Debug.Log("Triggered by [name] : " + other.gameObject.name);
     	if (other.gameObject.tag == "Paper"){
     		Paper += 1;
     		Debug.Log("A paper was picked up. Total papers = " + Paper);
     		Destroy(other.gameObject);
     	}
     }
    
     function OnGUI()
     {
     	if (Paper < paperToWin)
     	{
     		GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "" + Paper + " Papers");
     	}
     	else
     	{
     		GUI.Box(Rect((Screen.width/2)-100, 10, 200, 35), "All Papers Collected!");
     	}
     }
    
  • Edit : uploaded an example using this script.

Here is a link to an example : http://www.alucardj.net16.net/unityanswers/PickUpPaper.html

Here is a link to the script on the example : http://www.alucardj.net16.net/unityanswers/ScriptPickUpPaper.js