Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines

scoring

A topic by Marko Vuger created Aug 27, 2019 Views: 356 Replies: 4
Viewing posts 1 to 5

this is where the code should goHey, I need help with the code,  coding isn't my strongest side so that's why I am asking for help.So the problem is I am not sure how do I code scoring system, I used TMP to make a score counter and script for it but I don't know how  I can make in enemy script so when it's killed you get 100 points(example).this is simple scoring system setup

Simplest way is to make reference to score script in enemy script and change scoreValue before Destroy() dunction, also you not need "static" int

(3 edits)

public scoring scoreScript; // in enemy script, then drag object with score script to varible field in editor

And

scoreScript.scoreValue += 100; // before Destroy() in enemy script

Submitted

When enemy is killed

scoreValue = scoreValue + 100;

For UI elements, avoid putting them in Update(). I like to put them in LateUpdate().

Submitted

I suppose it depends on how you've designed a lot of your game, but a fast and simple way would be creating a global singleton that holds the player's score. Then any script can quickly call a method that sets the score, or even sets it directly.