简体   繁体   中英

Turn off toggle box and graphic when game starts

So this should be a simple answer but I cannot seem to find it anywhere. In Unity, I have a toggle box I want to turn off when the game starts, but unlike most game objects or text, SetActive does not work with toggle boxes. What is the command to turn the graphic off?

public void StartGame () {

    mainText.SetActive (false);
    startButton.SetActive (false);
    StartCoroutine (SpawnBalls ());
    //Turn off toggle box graphic
    playing = true;
}

public void AddBall () {
    if (ballBox.isOn) {
        ballNumber = 3;
        //Debug.Log ("yes");
    } else {
        ballNumber = 2;
    }

If I understand you correctly you want to be able to remove the display of the toggle on the start of the game? If so set a reference to the toggle you want to click on and off heres a small example:

Toggle T = GameObject.Find("myToggle").GetComponent<Toggle>();
T.gameObject.SetActive(false);

Make a reference to it and you should be able to click it of and on as you need it tested it out on a game I'm working and it worked for me let me.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM