- Home /
Gem System help! For Mini Game!
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.
You are using C# but your GetComponent looks like UnityScript style. I did not know it would work. $$anonymous$$aybe try the proper way:
GetComponent<Type>();
And remove the ""
Please just post code as code, don't mess with images. Also don't post comments as answers.
Answer by phodges · Nov 03, 2012 at 06:48 PM
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.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Show GUITexture by picking an item. 0 Answers
Problem with BRDF Shader 1 Answer
Plinko Collision Problem 2 Answers
Pause Menu 5 Answers