Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
  • Help Room /
avatar image
0
Question by kaboose1066 · Mar 31, 2019 at 08:50 AM · transformtextscaleslidermathf.lerp

Scale slider min to max value based on parent object scale descending

So, I'm real new to scripting and I'm lost. I've got a slider which counts up from -500 to 1000 of which I can set the time using mainSlider.value += 5.0f; which is great but I need it to be speed dependent on how quickly it's parent is scaling down in size.

I have the scaling down object working how I like having a minSize, scaleRate, and Current scale (scale). Here's the code for that.

 public float minSize;
 public float scaleRate;
 public float scale;

 private void Update()
 {
     transform.localScale = Vector3.one * scale;
     scale -= scaleRate * Time.deltaTime;
     if (scale < minSize) Destroy(gameObject);
 }

and here's the code for the slider min to max over time using 5.0f as a place holder for now.

 public Slider mainSlider;
 public int minValue;
 public int maxValue;

 private void Start()
 {
     mainSlider.value = minValue;
 }

 private void Update()
 {
     if (mainSlider.value <= maxValue)
     {
         mainSlider.value += 5.0f;
     }
 }

All I need is for the +=5.0f to be not set solid like that but be at the minValue when the parent object is at it's start size and the maxValue to be reached when the minSize of the parent object is reached.

I've been playing around with mathf.lerp where the 0.5f is but I can't figure out how to get the t to scale the slider value properly, if I call the scale from the parent object it just forces the value to 0.

any thoughts??? First time I've gotten properly stuck.

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image fafase · Mar 31, 2019 at 08:52 AM 0
Share

You can set the $$anonymous$$/max value of a slider in the Inspector or by code:

https://docs.unity3d.com/ScriptReference/UI.Slider-$$anonymous$$Value.html https://docs.unity3d.com/ScriptReference/UI.Slider-maxValue.html

this will clamp the value within those boundaries.

avatar image kaboose1066 fafase · Mar 31, 2019 at 11:58 AM 0
Share

I have set the $$anonymous$$ and max values and have made them increase from $$anonymous$$ to max with a scalespeed variable already, what I need is for the slider to be directly linked to it's parent objects scale transform, so when I slide the slider it changes the size of the objects scale, hope this makes more sense?

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by fafase · Mar 31, 2019 at 06:59 PM

what I need is for the slider to be directly linked to it's parent objects scale transform, so when I slide the slider it changes the size of the objects scale,

Based on that comment, you simply want to have your scale to listen to the changes of the slider.

https://docs.unity3d.com/ScriptReference/UI.Slider-onValueChanged.html

 public Slider slider;
 void Start()
 {
       mainSlider.onValueChanged.AddListener(SliderChanged);
 }
 
 private void SliderChanged(float value)
 {
        transform.localScale = new Vector3(value, value,value);
 }

This is simple and I'll leave it to you to set the scale properly. But the concept is to use the event from slider so you know when it is changed.

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image kaboose1066 · Apr 01, 2019 at 03:43 AM 0
Share

Yep, I was way over complicating it, thank you!

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

204 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Content Size Fitter should scale only in one direction 0 Answers

Stop counting score when Game over : don't know how to do it... 0 Answers

Problem with Slider 1 Answer

Player Prefab scale automatically goes to 1 x 1 x 1 whereas I have set it to 0.48 x 0.48 x 0.48 1 Answer

Built game on Android has GUI text pink, and slider menu has disappeared. 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges