Solution: Select Next Unit (On Current Selected Unit Death)

Hello everybody, after reading some posts about this lesson, I used one comment of Code Monkey to create the proposed solution. Original post below:

The solution.

  1. In UnitActionSystem.cs scritp, in Start, listen to the turn change event.
    immagine

  2. On the page end, implement the new function as in the followinf image

With this cose the next unit will be selected if the current one is dead. If all are dead there is a debug line sayng the game is over.

Thanks to Hugo for the tip!

5 Likes

Nice!
You should probably use IsDead() instead of GetHealthNormalized() == 0, it makes the code a bit more intuitive

3 Likes

You area right, best practices first!
Here the new solution, just to help others if they need it.

  1. Created the public IsDead function on Healthsystem
    immagine

  2. Exposed it by the unit script like we did with GetHealthNormalized
    immagine

  3. And update the condition of the TurnSystem_OnTurnChanged function in UnitActionSystem

5 Likes

I think it’s not correct to check Unit.isDead since the Object could be deleted at this point from the scene.
Checking for null seems to work.

Privacy & Terms