- Home /
Duplicate Question / Multiple Part Question
Stacking Game - Add +1 Score on Collision - Show on GUItext
I'm working on a stacking game and I now need to add a scoring system. Basically, each time the user is able to properly stack a box on top of another box, the user should achieve 1 point. The point should display on my counter.
For a reference: https://www.youtube.com/watch?v=CJH5Jjjy01A
I know there are a few examples online on how to do this, but I haven't been able to get them to work on my game.
Unity Answers is for specific technical questions. When asking a question please provide as much information as possible: What you want, what you have tried, what you expected to happen and what actually happens. Also provide any applicable scripts.
As you said, there are many examples of a scoring system on Unity Answers and other places. Please start on the system yourself and when you get stuck on anything specific then you are welcome to ask here. Just remember to give as much detail as possible.
Answer by PhoenixBlackReal · Jan 29, 2015 at 11:41 PM
You should really define what you mean by "properly." If they are supposed to be really well aligned - then you could calculate a general position. Say a box is 1x1x1 size, and is as 0, 0, 0 position. Then the perfect point of the other box is position 0, 1, 0. You could check by how close the transform position of the currently stacked box is to that point. Using collision like that wouldn't work too well, because a collider could hit the side of the box and still get a point. Another option is to use a raycast and calculate the distance from the currently stacked object straight down. In this case, if the raycast distance is around 0.5f, then the box is above another box and is stacked somewhat properly. And yet again, another thing I can think of is adding a small round collider on the top of the box, say 0.5x0.1x0.5 size. And the same kind of collider on the downside of the other box. When these colliders touch - the object is positioned properly. I hope you get the idea and will make something from here.
Thanks for the reply. Well, the core of my issue is basically getting a scoring system in place. From what I understand, I need a script that detects a collision then registers a point, and then another script for displaying the score. If there is a way to combine both into one script, that would be great.
Follow this Question
Related Questions
How to make an online scoreboard -1 Answers
Multiplayer ScoreBoard not Updating Correctly 0 Answers
How to save score for survival time? 1 Answer
Saving travelled distance as a score 1 Answer