Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Caiuse · Apr 14, 2011 at 07:56 PM · percentage

How do I use one variable to control the progress of two Mathf.Clamp

I have two variables:

varOne = Mathf.Clamp(progress,0,100)
varTwo = Mathf.Clamp(progress,30,40)

Both with completely different Mathf.Clamp values, but both with the control variable of "Progress". I want progress to be "clamped" between 0 & 100 and to control both my variables (like a percentage).

For example if Progress = 50 then varOne = 50 and varTwo = 35 both variables will be at 50%

Comment
Add comment
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

1 Reply

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

Answer by Mortennobel · Apr 14, 2011 at 08:00 PM

Try to take a look at lerp: http://unity3d.com/support/documentation/ScriptReference/Mathf.Lerp.html

The code should look something like:

varOne = Mathf.Lerp(0,100,progress/100.0)
varTwo = Mathf.Lerp(30,40,progress/100.0)

Note that Lerp also clamps the value.

Comment
Add comment · Show 6 · 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 Caiuse · Apr 14, 2011 at 08:09 PM 0
Share

Thanks but I'm failing to see how this helps, It works almost the same as my $$anonymous$$athf.Clamp, how can I keep the values between "30,40" but use a controlling value with a range of 0 to 100?

avatar image Caiuse · Apr 14, 2011 at 08:11 PM 0
Share

Sorry I think I cracked it, I was using a float as the controlling var, so It appeared to be working the same, realised I needed to change the controlling var to a int.

avatar image Caiuse · Apr 14, 2011 at 08:13 PM 0
Share

Strangely that only works as a float 0.0 - 1.0, but none the less it'll do. Cheers

avatar image Mortennobel · Apr 14, 2011 at 08:15 PM 0
Share

Or you could change all vars to floats

avatar image Mortennobel · Apr 14, 2011 at 08:16 PM 0
Share

Lerp only interpolates between 0.0 and 1.0 (that's why I divide by 100) in the code example above

Show more comments

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

No one has followed this question yet.

Related Questions

Simple Maths Problem (I Suck At Maths) 2 Answers

probability of child Game objects 1 Answer

Calculating Percentages for an if Statement in JS 2 Answers

How to find % along path between N points 2 Answers

a variable that when an object is tilted 0º = 0 and 90º = 1 2 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