Search Unity

[Solved]FixedUpdate not recognizing changed bool value from an Update in another Class

Discussion in 'Scripting' started by hyiero, Jan 6, 2016.

  1. hyiero

    hyiero

    Joined:
    Jun 12, 2015
    Posts:
    7
    I have two classes currently an InputManager Class and a Shot Manager class. In the Input Class I am checking for when a mouse button is down whenever it is down I am changing a bool value in the ShotManager class to true. But in the fixedUpdate inside of the shotmanager it still says this bool value is False. I am calling a getValue method in the Update Method in the InputManager and it is consistently reporting the value is true even though the fixedUpdate in the ShotManager is reporting this as false. How is this possible?

    I could always do both the fixedupdate and update in the same class and it works but I am trying to decouple Inputs away from any logic

    Inside the InputManager
    Code (CSharp):
    1.         public void Update()
    2.         {
    3.             if(Input.GetMouseButton(0))
    4.             {
    5.                 shotManager.ActivateChargeShot(true);
    6.             }
    7.             Debug.Log("ShotBeingCharged inside of InputManager is: "+ shotManager.GetChargeShot());
    8.         }
    The Above debug always reports as True as soon as I have pressed the mousebutton

    And the below debug always reports as false inside the fixedupdate, even after I have pressed the mousebutton and the value being returned to the inputmanager always says its true
    Inside the ShotManager
    Code (CSharp):
    1.         public void FixedUpdate()
    2.         {
    3.             Debug.Log("ShotBeingCharged inside of ShotManager is: : " + shotBeingCharged);
    4.             if(shotBeingCharged)
    5.             {
    6.                 ChargeUpShot();
    7.             }
    8.  
    9.         public bool GetChargeShot()
    10.         {
    11.             return shotBeingCharged;
    12.         }
    13.  
    14.         public void ActivateChargeShot(bool active)
    15.         {
    16.             shotBeingCharged = active;
    17.         }
    18.