Hi game developers,
I made a mini game for my self to get better with Unity 3D and while scripting,
I wanted to do something but I couldn’t figured it out by myself.
I wan’t to make a Gem System (Code Below):
And for Settings (Code below):
This is it, both scripts don’t has an error or something else. But after I collect 1 gem and if I collect the next gem, the gem is destroys but, It don’t counts on my guiText.
And it don’t shows the Debug.Log(“”) messages.
Kind regards,
helloiam.
The way you’ve modelled this, every object with a ‘spin’ component will also have a ‘Settings’ component, rather than sharing the settings globally. So what can we expect to happen?
- Settings: Begin life with numGems = 0 and do nothing
- Player trips a trigger in one of your objects with a spin component
- spin prompts its Settings component to addGems
- Settings updates its numGems to 1 and sets GUI text
- spin kills its gameobject, taking it and Settings with it
Each and every gem will do the same thing, so it can never do anything other than set your text to one. There are lots of ways to fix this - for example, one thing you could do is make a single Settings object in the scene and reference that whenever the gem count is to changed.
By the way, I agree with the other comment: you should try and post formatted code. It’s much more accessible than screen captures of code.