Skip to main content
added toggle button and the constructor
Source Link
ClaudioA
  • 145
  • 2
  • 9

This is the code for the button:

public void ShowIt()
{
            ec.t1Bool = GUI.Toggle (new Rect (25, 55, 100, 50), ec.t1Bool, "Turbina 2 MW");

            ec.t2Bool = GUI.Toggle (new Rect (25, 95, 100, 50), ec.t2Bool, "Turbina 3 MW");

            ec.t3Bool = GUI.Toggle (new Rect (25, 135, 100, 50), ec.t3Bool, "Turbina 1 MW");

            GUI.Box (new Rect (Screen.width - 100, 60, 80, 25), ec.prod.ToString ());      // PRODUCED ENERGY
        
        }

This is where the object instance is created (it is in the same script as the button):

public class PlayState : IStateBase
    {
        private StateManager manager;
        private HydroElectric ec;
        public PlayState (StateManager managerRef)
        {
            manager = managerRef;
            Debug.Log ("Constructing PlayState");
            ec = new HydroElectric();
        }

Any hint?

Any hint?

This is the code for the button:

public void ShowIt()
{
            ec.t1Bool = GUI.Toggle (new Rect (25, 55, 100, 50), ec.t1Bool, "Turbina 2 MW");

            ec.t2Bool = GUI.Toggle (new Rect (25, 95, 100, 50), ec.t2Bool, "Turbina 3 MW");

            ec.t3Bool = GUI.Toggle (new Rect (25, 135, 100, 50), ec.t3Bool, "Turbina 1 MW");

            GUI.Box (new Rect (Screen.width - 100, 60, 80, 25), ec.prod.ToString ());      // PRODUCED ENERGY
        
        }

This is where the object instance is created (it is in the same script as the button):

public class PlayState : IStateBase
    {
        private StateManager manager;
        private HydroElectric ec;
        public PlayState (StateManager managerRef)
        {
            manager = managerRef;
            Debug.Log ("Constructing PlayState");
            ec = new HydroElectric();
        }

Any hint?

deleted 14 characters in body
Source Link
ClaudioA
  • 145
  • 2
  • 9

So, I have a toggle button to change a bool value, in this script 't1Bool'. The toggle button is working because when I use a Debug.log I can see the value changing from true o false when I press the button. When using the Debug.log with the variable turbina1 the value is always zero. I already checked the if condition syntax and don't know why this value is not being updated.

using System;
using UnityEngine;
namespace Assets.Code.PowerPlants
{
    public class HydroElectric
    {
        public bool t1Bool;
        public bool t2Bool;
        public bool t3Bool;

        public static int turbina1;
        int turbina2;
        int turbina3;

        public float prod;

        public HydroElectric ()
        {   
         t1Bool = true;
         t2Bool = true;
         t3Bool = false;
         prod = 0f; 
        }

        public float HydroControlPanel ()
        {
            turbina1 = t1Bool ? 2 : 0;
            turbina2 = t2Bool ? 3 : 0;
            turbina3 = t3Bool ? 1 : 0;
            
            prod = turbina1 + turbina2 + turbina3;
            Debug.Log (turbina1);
            return prod;
        }
    }
}

Any hint?

So, I have a toggle button to change a bool value, in this script 't1Bool'. The toggle button is working because when I use a Debug.log I can see the value changing from true o false when I press the button. When using the Debug.log with the variable turbina1 the value is always zero. I already checked the if condition syntax and don't know why this value is not being updated.

using System;
using UnityEngine;
namespace Assets.Code.PowerPlants
{
    public class HydroElectric
    {
        public bool t1Bool;
        public bool t2Bool;
        public bool t3Bool;

        public static int turbina1;
        int turbina2;
        int turbina3;

        public float prod;

        public HydroElectric ()
        {   
         t1Bool = true;
         t2Bool = true;
         t3Bool = false;
         prod = 0f; 
        }

        public float HydroControlPanel ()
        {
            turbina1 = t1Bool ? 2 : 0;
            turbina2 = t2Bool ? 3 : 0;
            turbina3 = t3Bool ? 1 : 0;
            
            prod = turbina1 + turbina2 + turbina3;
            Debug.Log (turbina1);
            return prod;
        }
    }
}

Any hint?

So, I have a toggle button to change a bool value, in this script 't1Bool'. The toggle button is working because when I use a Debug.log I can see the value changing from true o false when I press the button. When using the Debug.log with the variable turbina1 the value is always zero. I already checked the if condition syntax and don't know why this value is not being updated.

using System;
using UnityEngine;
namespace Assets.Code.PowerPlants
{
    public class HydroElectric
    {
        public bool t1Bool;
        public bool t2Bool;
        public bool t3Bool;

        int turbina1;
        int turbina2;
        int turbina3;

        public float prod;

        public HydroElectric ()
        {   
         t1Bool = true;
         t2Bool = true;
         t3Bool = false;
         prod = 0f; 
        }

        public float HydroControlPanel ()
        {
            turbina1 = t1Bool ? 2 : 0;
            turbina2 = t2Bool ? 3 : 0;
            turbina3 = t3Bool ? 1 : 0;
            
            prod = turbina1 + turbina2 + turbina3;
            Debug.Log (turbina1);
            return prod;
        }
    }
}

Any hint?

Source Link
ClaudioA
  • 145
  • 2
  • 9

Inline If failing to update variable value

So, I have a toggle button to change a bool value, in this script 't1Bool'. The toggle button is working because when I use a Debug.log I can see the value changing from true o false when I press the button. When using the Debug.log with the variable turbina1 the value is always zero. I already checked the if condition syntax and don't know why this value is not being updated.

using System;
using UnityEngine;
namespace Assets.Code.PowerPlants
{
    public class HydroElectric
    {
        public bool t1Bool;
        public bool t2Bool;
        public bool t3Bool;

        public static int turbina1;
        int turbina2;
        int turbina3;

        public float prod;

        public HydroElectric ()
        {   
         t1Bool = true;
         t2Bool = true;
         t3Bool = false;
         prod = 0f; 
        }

        public float HydroControlPanel ()
        {
            turbina1 = t1Bool ? 2 : 0;
            turbina2 = t2Bool ? 3 : 0;
            turbina3 = t3Bool ? 1 : 0;
            
            prod = turbina1 + turbina2 + turbina3;
            Debug.Log (turbina1);
            return prod;
        }
    }
}

Any hint?