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 LaurensiusTony · Dec 13, 2013 at 01:48 AM · scaleguitexture

Scaling guitexture gameobject

Hi, i'm working for mobile games and i have currently 3 guitexture gameobject that use for virtual joystick, how can i scale these guitexture? since i did not drawing this texture using script so it's not draw by calling function OnGUI() so i can't use this code for scaling

 function OnGUI()
 {
     var svMat = GUI.matrix;
     scale.x = Screen.width/originalWidth;
     scale.y = Screen.height/originalHeight;
     scale.z = 1;
     GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
 
 drawPause();
 
 GUI.matrix = svMat;
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 FirePlantGames · Dec 13, 2013 at 02:08 AM 0
Share

i generely find code WAYYYYY easier to use than the GUITexture component

avatar image LaurensiusTony · Dec 13, 2013 at 03:05 AM 0
Share

yea but unfortunately i don't have any idea how to make guitexture from code to work like joystick so i kind of stuck using this guitexture component

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by robertbu · Dec 13, 2013 at 05:22 AM

One solution is to modify the GUITexture.pixelInset. You can resize by changing the 'width' and 'height', but if you have it anchored in the center, you must also adjust the 'x' and 'y'.

Here is a function that resizes the GUITexture on the same game object as this script:

 function ResizeGUITexture(widthScale : float, heightScale : float) {
     var rect = guiTexture.pixelInset;
     rect.width *= widthScale;
     rect.height *= heightScale;
     rect.x = -rect.width / 2.0;
     rect.y = -rect.height / 2.0;
     guiTexture.pixelInset = rect;
 }

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 LaurensiusTony · Dec 13, 2013 at 05:24 AM 0
Share

wow thank you ,and what is the value for widthscale and heightscale? screen resolution?

avatar image robertbu · Dec 13, 2013 at 06:29 AM 0
Share

It is a fraction. So if you want to size it to 1/2 size on width and height, you would call it:

 ResizeGUITexture(0.5, 0.5);
avatar image robertbu · Dec 13, 2013 at 06:31 AM 0
Share

Note if you wanted to use pixels rather than fractions, you can change the code to:

 function ResizeGUITexture(w : float, h : float) {
     var rect = guiTexture.pixelInset;
     rect.width = w;
     rect.height = h;
     rect.x = -rect.width / 2.0;
     rect.y = -rect.height / 2.0;
     guiTexture.pixelInset = rect;
 }
avatar image LaurensiusTony · Dec 13, 2013 at 06:37 AM 0
Share

hmm so i just need to detect what resolution being used by the game and giving some value to ResizeGUITexture that will make gui texture big enough to use into that screen resolution?

or maybe i just put all this ResizeGUITexture script inside my gui.matrix? so i treat it like other guitexture?

avatar image robertbu · Dec 13, 2013 at 07:37 AM 0
Share

GUI and GUITexture are two different things. GUITextures do not use the GUI.matrix. As for scaling for different displays, I start by calculating the ratio of the authored screen resolution to the device screen resolution. Say you did all of your authoring for a device that has a height of 1024. You could do in a script attached to the GUITextures in start:

 function Start() {
     var fraction = Screen.height / 1024;
     ResizeGUITexture(fraction, fraction);
 }
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

17 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

Related Questions

[CLOSED] Pixel Inset ---> transform scale convert 0 Answers

Scaling a GUITexture using iTween 1 Answer

Scale menu to fit webplayer with fullscreen on/off 0 Answers

Bulletproof way to do resolution independant GUI scaling? 2 Answers

Scale GUI Texture to current screen size? 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