Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Update sliders, toggles and scrollbar if menu is toggled off.

Discussion in 'UGUI & TextMesh Pro' started by jimvanmil, Sep 23, 2014.

  1. jimvanmil

    jimvanmil

    Joined:
    Jun 20, 2011
    Posts:
    20
    I have serveral menus build-in.

    One menu is a control menu with some sliders, scrollbars and toggles.

    What is the best way to get these updates if the menu is off.

    If i use one key to set the value up to 0.5 and open the menu the value will be 0.

    Does somebody have a solution.

    written in JS

    Kind regards
     
  2. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    I'm doing this right now in my current project. My menu is deactivated, I set it's sliders to my desired values, then I activate the menu. It works great, I don't understand exactly where you're having trouble.
     
  3. jimvanmil

    jimvanmil

    Joined:
    Jun 20, 2011
    Posts:
    20
    how did you do that.
     
  4. User340

    User340

    Joined:
    Feb 28, 2007
    Posts:
    3,001
    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;
    4.  
    5. public class NewBehaviourScript : MonoBehaviour
    6. {
    7.    public GameObject menu;
    8.  
    9.    void Start () {
    10.  
    11.       //set the ui elements how you want
    12.       menu.transform.Find("Volume Slider").GetComponent<Slider>().value = 0.5f;
    13.       menu.transform.Find("Toggle").GetComponent<Toggle>().isOn = true;
    14.  
    15.       //activate the menu
    16.       menu.SetActive(true);
    17.    }
    18. }
     
  5. jimvanmil

    jimvanmil

    Joined:
    Jun 20, 2011
    Posts:
    20
    This is the key input to control with the slider menu on.

    var slider : Slider;
    static var molens : float = 0.0;


    function Update () {

    if (Input.GetKey("q")) {slider.value +=0.01;}
    if (Input.GetKey("a")) {slider.value -=0.01;}

    molens = slider.value *75;
    }

    Now in the off state of the menu i press "q" and if the menu is going on the value is 0.

    It must be JS