Finding value of an int?

Hi guys,

I’m trying to read the value of the StuffCollected int so that when it reaches 25 the level will change. Not too sure about it and could use a nudge in the right direction. Here’s what I have so far, not sure where to go from here.

Cheers.

static var StuffCollected : int = 0;


function Update () {

guiText.text= "Stuff: " + StuffCollected;

if (StuffCollected == 25){


Application.LoadLevel ("Level2");

		}
}

This code seems ok - are you having any problem? Anyway, be aware that a static variable is created and initialized when the program begins, and survive till the end of the program. Due to this, its value will still be 25 when Level2 is loaded, thus you must zero it at Start or Awake if you plan to use it again.

The script above must be attached to the GUIText object, and you can increment SuffCollected in other scripts using something like this:

GuiScript.StuffCollected += 1;

where GuiScript is the above script’s name.