I have a component gameState Attached to one gameobject called GameState:
public class gameState : MonoBehaviour
{
public Context stateMachine;
private void Awake()
{
PlayerGameobject p = GameObject.Find("Player").GetComponent<PlayerGameobject>();
stateMachine = new Context(new Playing(), p);
}
On another gameObject I have this component:
public class PlayerGameobject : MonoBehaviour
{
void Start()
{
gameState = GameObject.Find("GameState").GetComponent<gameState>();
}
}
When I try to use gameState within PlayerGameobject's Update method I find that stateMachine is null.
if (gameState.stateMachine.CurrentState == "Playing"){}
// ^^^^ null
why is statemachine null? I initialized it in awake which should run before start. gameState is not null and other public variables assigned in Editor are not null.