0
\$\begingroup\$

In my game there is a game manager that interacts with all players and is able to change whether a player is actionable by accessing their script. However, the Game manager script simply refused to change the actionable bool. There were no errors produced either. Even changing all of the private variables to public didn't change anything. What am I doing wrong?

My player script:

public class PlayerManager : MonoBehaviour
{
    public bool actionable;

    void Start()
    {
        actionable = false;
    }
}

My Game Manager Script:

public class GameManager : MonoBehaviour
{
    private PlayerManager playerScript;
    public List<GameObject> players = new List<GameObject>();
    private GameObject currentPlayer, seats;
    private int turn;

    void Start()
    {
            
        turn = 0;
        currentPlayer = players[turn];
        playerScript = currentPlayer.GetComponent<PlayerManager>();
        playerScript.actionable = true;
    }
}
\$\endgroup\$
4
  • \$\begingroup\$ I notice both these scripts set actionable in their Start method. Is it possible that the player's Start is running after the game manager's Start, and overwriting the value that it set? Did you consider moving the player's initialization to Awake or using Script Execution Order settings to ensure the game manager gets the last word here? \$\endgroup\$
    – DMGregory
    Dec 29 '21 at 11:40
  • 1
    \$\begingroup\$ You could set default value of actionable in the GameManager right away to false and not in Start as well. \$\endgroup\$
    – Zibelas
    Dec 29 '21 at 12:46
  • \$\begingroup\$ I changed the Script Execution order settings so that the PlayerScript would run first, but it still didn't change the fact that the GameManager script isn't able to change the bool. The bool isn't used in the update void either so it is not like something is constantly setting it to false. \$\endgroup\$ Dec 30 '21 at 10:22
  • \$\begingroup\$ The reason the GameManager script switches it to true at the beginning is that I want all other players except the one that is currently controllable to be idle, which means that every player except for the current one should be set to false. \$\endgroup\$ Dec 30 '21 at 10:25

You must log in to answer this question.

Browse other questions tagged .