- Home /
Scoring/Counting how many specific objects are placed on a specific plane.
Hello, I'm a beginner at unity and I've been stuck at this issue for quite sometime. My game is 3D and I'm wanting to pick up a specific object with the tag "Runner" onto a specific plane (Counter). The Counter would then display the amount of Runners touching the the counter on the screen with (Score). I've already created a UI text box on the screen, the picking up system down but the thing I'm stuck on is if I should put the counting script on the Text box or on the plane. If anyone has some insight on this kind of scoring system like advice, it would really help out!
Thanks for reading -Sporks
PS: If this is important to know, the Runners are not AI's yet, so AI code isn't involved in the game yet.
It would work in both cases, depending on implementation, so technically it's doesn't matter.
On the other hand, from design perspective, textbox is just visual representation of your logic, it doesn't 'count' objects, it shows their count. The plane is the best place for script: it detects objects (via trigger collider or whatever), selects runners from them and then sends runners count to your UI.
Decoupling UI and app logic anywhere you can is a very good practice.
Answer by Anis1808 · Dec 06, 2019 at 04:33 AM
You could create a script and attach it to the counter. This script would contain a variable of type int of the amount of Runners. This value would be incremented from another script, the one that moves the Runners on top of the platform using GetComponent().amoutOfRunners++; They you would either update the score text in the Update function or whenever the value amountOfRunners changes using a function. Good Luck ! I gave you explanation on how to do it but if you need code tell me.