There are easier way to Increase score

Hi! In Complete C# unity gamedev course (video 94) we were calling method FindObjectOfType. It takes lots of resources of the computer. So there are more effective way to do this, i guess.

My version of scorer down below.
image

The idea is using static var is Scorer class. Static vars are initiated once for all of the examples of this variable. So if we have class with static var, and we have two examples of this class. Value of this vars will be the same all the time.

3 Likes

Yes using static can be a way to avoid FindObjectOfType. But your solution is only half better.
Make your AddScore method a static function so you don’t need to instantiate a Scorer to every enemy, just do Scorer.AddScore(amount) (Scorer = the class).
I think he did not use static stuff because it would be too much to grasp as the same time to begginers.

Privacy & Terms