State Machine help

Okay, this is the first time I’m actually trying to work with StateMachines[enums] I’m trying to optimize my code, so I’d like to use Enums to control the game state. I have a basic system set up like so

This is in the Game Manager.cs script

public enum GameState {
		
	Start,
	Playing,
	Paused,
	Destroyed
	
}

I also declare this in the same script

public GameState state;

Then use this in the start function

state = GameState.Start;
		
			
		if(state == GameState.Start){
		enemyCount = maxSpawnCount;
		SpawnEnemies();
		state = GameState.Playing;
		}

All this works, but the problem is my Player.cs scripts inherits from the game manager

public class Player : GameManager {

so the GameState variable is shown on the player GameObject, and when the games starts the gameManager Game state variable changes but it doesnt change on the player GameObject. how do I fix this?

EDIT:
Making the variable protected seems to fix the problem so I guess this question was a waste… I’ll leave it open if anyone knows a better way…

Why is your Player inheriting from your GameManager? That sounds like a really fucked up way to structure things.

I use managers but just use getcomponent to access any info.

enums are not a great way to make a state machine in my experience; you have to check them all the time, which will make for complex code. You should make the state a nested class.

language? but things in my game need other things to work properly… . there are many things not unique to the player that the player needs to interact like the points… anyways everything works we; actually better than ever… so yeah…

Language aside he’s pretty right on. Sub-class should generally be considered an is a relationship. So a Duck is a Bird is a Creature. You are saying that a Player is a GameManager? Sounds pretty strange.

Why don’t you just reference the game manager from your player? Or if that doesn’t fit you situation make use of Unity’s component system (different behaviours shared across different objects).

I could do it that way using GetComponent, I’ll decide in the end… It could be safer to do it that way i when I think about it…

Yeah using Get Component doesnt work… I dont get any errors in my script but it doesnt work… If the way I’m doing it is wrong can anyone suggest another way?