Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Controlling behavior of objects with non-exposed properties

Discussion in 'UGUI & TextMesh Pro' started by WoodsBagot, Oct 17, 2014.

  1. WoodsBagot

    WoodsBagot

    Joined:
    Mar 6, 2014
    Posts:
    8
    I am trying to create a slider to control the "Time of Day" asset's "hour" property. It is not available to me as an exposed property when I select it in the "On Value Changed" area.

    Sorry - but I have no experience, yet, in scripting in Unity (although I have general scripting experience). I was told to control "TOD_Sky.Instance.Cycle.Hour" from my own script.

    How do I connect this slider to my own script to control this property? Is there a good sample out there, or a crash course I should read up on?
     
    David-Lind likes this.
  2. jdi_knght

    jdi_knght

    Joined:
    Nov 6, 2013
    Posts:
    25
    This is just a random shot-in-the-dark guess (I don't have that asset), but I'm assuming the variable is within a static object which is would explain why it can't be accessed directly by the GUI.

    Try creating your own C# script that contains something like this (just create it after the empty start/update methods that are autopopulated into a new script):

    Code (CSharp):
    1. public void ChangeSlider (float sliderValue) {
    2.     TOD_Sky.--let_auto_complete_in_mono_help_find_the_path_to_hour = sliderValue;
    3. }
    ...and then attach that script to an object (the one containing the slider is fine for now). As a note, type the TOD_Sky. manually in monodevelop (don't copy/paste, otherwise the autocomplete won't come up), and assuming it's set up the way I'm guessing, it'll usually show you what you can access and you can muddle your way through there.

    You would then have the "On Value Changed" connected to the script you created (which should have an accessible ChangeSlider() method).

    ---

    Again, this is a shot in the dark because I have no idea how that asset is set up and am only guessing, but it might be worth a try.
     
  3. WoodsBagot

    WoodsBagot

    Joined:
    Mar 6, 2014
    Posts:
    8
    jdi_knght - you are a fantastic human being.
    This worked perfectly!

    using UnityEngine;
    using System.Collections;

    public class TOD_update : MonoBehaviour {

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

    }
    public void ChangeSlider (float sliderValue) {
    TOD_Sky.Instance.Cycle.Hour = sliderValue;
    }
     
    David-Lind likes this.
  4. David-Lind

    David-Lind

    Joined:
    Jul 25, 2013
    Posts:
    2
    Hi guys, I'm trying to make a slider with NGUI that will change the time of day hour but do you know what i need to put into the scroll bar to make it update the Time of Day?
     

    Attached Files: