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

question about the slider and how to attach it to a variables value

Discussion in 'Getting Started' started by Sylvir, Apr 25, 2015.

  1. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    what would be the best way to make a slider connect to a variable and slide up incrementally as that value fills up?

    like an experience bar kind of thing.

    I have a slider in my scene, and I was thinking about it. i feel like i could get this to work by attaching the slider to my experience/rank script, then somehow telling it to be relitive to the experience values. I am un sure how to actually acomplish this though after messing around with it for a bit. Could someone give me an idea where i would go next from here? thanks
     
  2. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    The easiest way is to set Slider.value every time experience changes. You can do this inside the setter for experience.

    To do it without the experience knowing about the slider you can use an event, again triggered inside the setter for experience.

    To totally decouple the classes you can use reflection. But that's not a path you want to go down just yet if you are posting in the getting started section.
     
    FTCosta and Sylvir like this.
  3. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
  4. Sylvir

    Sylvir

    Joined:
    Mar 21, 2015
    Posts:
    396
    Thank you, I will check out those videos. I will have to remember in the future to try and check out the official unity videos too when i have a question they are done in a really great way. Atleast the ones ive watched so far