Categories

See More
Popular Forum

MBA (4887) B.Tech (1769) Engineering (1486) Class 12 (1030) Study Abroad (1004) Computer Science and Engineering (988) Business Management Studies (865) BBA (846) Diploma (746) CAT (651) B.Com (648) B.Sc (643) JEE Mains (618) Mechanical Engineering (574) Exam (525) India (462) Career (452) All Time Q&A (439) Mass Communication (427) BCA (417) Science (384) Computers & IT (Non-Engg) (383) Medicine & Health Sciences (381) Hotel Management (373) Civil Engineering (353) MCA (349) Tuteehub Top Questions (348) Distance (340) Colleges in India (334)
See More

Unity Array of Struct : When setting a variable of one of the array subscripts, it sets it for all of them

General Tech Learning Aids/Tools
Max. 2000 characters
Replies

usr_profile.png
Harsh Vashishth

User

( 6 months ago )

 

This is my struct that I have created.

public struct Bar
{

    private static float deltaTime = 1.0f;
    private static bool AutoRun = false;
    private static bool AutoRunBought = false;
    private static bool Start = false;


    // DELTA TIME
    public float GetDeltaTime()
    {
        return deltaTime;
    }
    public void SetDeltaTime(float _dt)
    {
        deltaTime = _dt;
    }
    public void IncrementDeltaTime(float _deltaIn)
    {
        deltaTime += _deltaIn;
    }
    public void DecrementDeltaTime(float _deltaIn)
    {
        deltaTime -= _deltaIn;
    }

    // AUTO RUN
    public bool GetAutoRun()
    {
        return AutoRun;
    }
    public void SetAutoRun(bool _autoBought)
    {
        AutoRunBought = _autoBought;
    }
    public bool GetAutoRunBought()
    {
        return AutoRun;
    }
    public void SetAutoRunBought(bool _autoBought)
    {
        AutoRunBought = _autoBought;
    }

    // START
    public bool GetStart()
    {
        return Start;
    }
    public void SetStart(bool _start)
    {
        Start = _start;
    }
}

In my other class I create an instance of that by calling

scr_Globals.Bar[] myBars = new scr_Globals.Bar[2];

in my Update I am doing

if (myBars[0].GetAutoRun() == true) 
    {
        myBars[0].IncrementDeltaTime (incrementBar1);
        if (myBars[0].GetDeltaTime () > 40.0f) {
            myBars[0].SetDeltaTime (1.0f);
            globals.IncrementTotalMoney(1.0f);
        } 
    }
    else 
    {
        if (myBars[0].GetStart() == 
			
        

what's your interest