0

I have the class PlayerController

public class PlayerController : MonoBehaviour
{
    bool isMoveable;

    public void Init()
    {
        isMoveable = false;
    }
    void Update()
    {
        ...
    }

    private void FixedUpdate()
    {
        if (isMoveable)
        {
            MovePlayer();
        }
    }

    public void EnableMovement()
    {
        isMoveable = true;
    }

    void MovePlayer()
    {
    }
}

I have class GameMaster

public the class GameMaster : MonoBehaviour
{
    PlayerController playerController;

    private void Start()
    {
        playerController.Init();
    }

    public void StartGame()
    {
        playerController.EnableMovement();
        uiManager.OnGameStarted();
    }
}

and I'm trying to start the game by clicking a button that activates StartGame(). But MovePlayer() never got called, but if I print Debug.Log(isMoveable) in EnableMovement, I get True.

I have tried to change isMoveable by int and enum but that didn't help.

Geeky Quentin
  • 2,469
  • 2
  • 7
  • 28
  • @LiorV please familiarise yourself with how unity works before trying to answer questions on it. `FixedUpate` is a Unity Event function, it is called via a specific engine mechanism – Jay May 01 '23 at 15:34
  • Maybe the Player object is not Active? In GameMaster.Start() add playerController.gameObject.SetActive(true); before the Init() call might help. – Dustin_00 May 01 '23 at 15:48
  • I would start with trying to log something inside of `PlayerController`'s `FixedUpdate`. If nothing prints in the console, then `PlayerController` might not be active like @Dustin_00 mentioned. – squidee_ May 03 '23 at 00:36

0 Answers0