- Home /
Collectables in C#
Hello
I've been working on a game, and in said game, the goal is to collect a certain number of notes before you can progress to the next level.
The only problem here is that I can't seem to figure out how to get this system to work. This is the code I have attached to an empty gameobject in the scene:
Then, in the PickUpNote script attached to the player, specifically at the part where the note model is destroyed, I've added this line:
Collectibles.collected++;
The problems I'm seeing now:
The errors in the Collectibles script. It doesn't seem to recognize the variables I just declared in the same script, and not even the 'if'-statement.
The GUI box doesn't seem to show itself.
I feel like I've made a very dumb and basic mistake but I can't seem to find it. Can anyone help me with this?
Answer by LukaKotar · Feb 19, 2015 at 07:23 PM
Your
if
statement lies outside of every function. Put the statement inside theOnGUI()
function.It should be
OnGUI()
instead ofonGUI()
.
Answer by hexagonius · Feb 19, 2015 at 07:24 PM
The if statement is outside any function. Within the if statement you assign to collected with = and should compare with ==
That too, =
is used to set, and ==
is used to compare. Good catch.