- Home /
Collision based scoring system
I am trying to create to what amounts to a bowling type game. I want to be able to throw a crate at some barrels and when the crate hits the barrels, it will generate a score.
It doesn't need to be complex, simply for each barrel the crate hits, you get 1 point or something.
I know basic scoring code but I don't know how to actually impliment something like this.
Any advice or direction would be greatly appreciated.
Answer by dannyskim · Nov 24, 2011 at 09:37 PM
Typically for something regarding tallying score, the best approach would probably to make a singleton game object that points are passed into. You may want to take a look at this link in order to get some additional insight, which is not authored by me:
http://answers.unity3d.com/questions/172315/sending-data-to-different-game-objects.html
Delegates / Events may be a complicated system for your particular application, and I know you said you wanted it to be simple, but this is one of the most elegant and efficient ways to handle these type of information passing events.
If something rudimentary is desired, than you can simple have an empty game object that just receives incrementing score values. So something basic would be for your score object (C#):
public class scoreKeeper : MonoBehaviour {
public int score;
void OnGUI()
{
// run score updating here with your "score" value
}
}
From you other scripts, you can simply do:
void OnCollisionEnter( Collision other )
{
if( other.name == "barrel" )
{
scoreKeeper.score += 1;
}
}
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Collision based scoring system 1 Answer
C# How to have weapon pickup 1 Answer
hide child object script - help 1 Answer
Instantiating at Collision Point. 2 Answers