Hey there. I’m new to Unity, and I’m working on my first simple game. Basically all you have to do is pick up four objects scattered around the area, and a the end screen pops up. The problem is that the script I wrote for it is not working. I attached the script to the player, but when I collide with an object, nothing happens. The counter doesn’t go up, and the object isn’t destroyed. The script is below, and again I’m very new to this. Don’t chop my head off if I made a simple mistake. Thank you for reading, and please help me out.
#pragma strict
var count : int;
private var text : GUIText;
function OnCollisionEnter(collision : Collision)
{
if(collision.transform.tag == "Finish")
{
count += 1;
Destroy(collision.gameObject);
}
print(Time.time);
}
function Update ()
{
if(count >= 4)
{
count = -1;
var g = new GameObject();
text= g.AddComponent(GUIText);
text.text = "The End";
text.transform.position = new Vector3(0.5F,0.5F,0);
text.anchor = TextAnchor.MiddleCenter;
}
}