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 /
avatar image
0
Question by Rukas90 · Feb 20, 2019 at 08:13 PM · guislidervaluemathfcalculate

How to calculate the width of the Rect, knowing current value and min and max values

Hello,
how can I calculate the width of the Rect, knowing current (in my case volume) value and min and max (in my case 0 and 1) values?

I am creating a custom GUI slider for my editor extension and I need to rescale the rect according on the current volume value.

I looked around and found the function Mathf.InverseLerp(); but was unable to figure out how to calculate the width still, can someone give some advice on this? It could be anything, I just want to understand on how to calculate these type of things? Thank you!

alt text

eg.png (83.2 kB)
Comment
Add comment · Show 5
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 Ymrasu · Feb 20, 2019 at 08:29 PM 0
Share

Rect class in Unity have a width property you can use. It you are referring to an UI object's RectTransform, you can access it with transform.rect.width. If you just want to do the math with the $$anonymous$$ and max, you can do max - $$anonymous$$.

avatar image Rukas90 Ymrasu · Feb 20, 2019 at 08:53 PM 0
Share

Hey, thanks for reply! I work with EditorWindows so I don't use RectTransform. And doing this (max - $$anonymous$$) won't really fix my issue as I want to rescale the rect width depending on the current value which is between 0 and 1. At least in my case right now. So this would not work unfortunately. :/ I want to recreate in short something like a slider. Like UI Slider for example. And Rect would be my slider fill.

avatar image Ymrasu Rukas90 · Feb 20, 2019 at 10:45 PM 0
Share

Sorry, I missed the part about it being an editor extension. Would you be able to use EditorGUIUtility.currentViewWidth to get the width of the editor window? Then the $$anonymous$$, max, and value all look to be percentages of that.

avatar image zereda-games Ymrasu · Feb 20, 2019 at 10:48 PM 0
Share

This doesn't help you much does it??

 if (GUI.Button(new Rect(Screen.width / 2 - 540, Screen.height / 1.5f - 100, 270, 50), "$$anonymous$$ain menu", YourGUIStyle))
avatar image zereda-games zereda-games · Feb 20, 2019 at 10:49 PM 0
Share

I build a lot of editor windows and Editor GUI can a see a snippet? aka a small block of code you are suck on.

0 Replies

· Add your reply
  • Sort: 

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

188 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

Related Questions

Can I show a numeric variable from the slider on the GUI? 1 Answer

Using Gui button to alter Slider Value 1 Answer

Horizontal Slider issue 0 Answers

Changing light intensity with a slider 2 Answers

How can i detect changes on a GUI slider? 1 Answer


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