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 Spittin_fire · Jul 06, 2011 at 10:26 AM · guitextureaspect-ratio

Aspect Ratio changes GUI Location Code in CSHARP

I have asked this question before but did not make it clear, so I shall try again. I have created a texture, that is for the background of my screen. On top of this background, with coding, not adding game objects, I have added 4 different gui textures of human faces that is to be the players characters. When I put them where they belong by coding the texture rec, I have tried using screen width height, adding their location through a variable of float, and I have tried declaring it directly within the rect, however my GUI faces move around the screen when the aspect ratio is changed. I tried building it and seeing if they would move around per different size of the screen and they do. They must STAY in PLACE!!! They cannot wander off and get lost. How in the world do you make this happen. Pixel inset did not work, adding game objects (not that I wanted to, just expiremening) of gui texture and putting them in the right place did not work. I have searched high and low to find out what is going wrong though everytime I think I have found it, it says to use screen width/heigt or pixel inset.... I tried and did not work. How do you keep gui in place when the aspect ratio is changed!?!?!?!?!?!?!?!?!?!?!?!?!

thanks in advance!

Comment
Add comment · Show 4
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 Graham-Dunnett ♦♦ · Jul 06, 2011 at 10:35 AM 0
Share

Did you follow the advice on the relevant documentation page and set the scale of the GUITexture's transform to (0,0,0)? (http://unity3d.com/support/documentation/Components/class-GuiTexture.html)

avatar image Graham-Dunnett ♦♦ · Jul 06, 2011 at 10:38 AM 0
Share

(and note that GuiTextures are game objects, just that they have the GuiTexture component attached to them)

avatar image Spittin_fire · Jul 06, 2011 at 01:07 PM 0
Share

Sir, When I tried the information you had given to me (And I really do appreciate your time and patience) I did take the transform down to zero for x,y,z, then I would move the portrait into place using the bit you told me about. When my first portrait was up at the top left side, and I shrunk my aspect ratio down, the image 100% vanished, I think it was still up in the imaginary top left corner that got destroyed when the aspect of the screen shrunk, I'm not sure, Perhaps I am doing it wrong, however I researched it across unity3d awsers, and also google, and found much of the same thing, I think there is like one REALLY small thing I am missing to this.. it has been a long 3 days of searching, trying.. and failure :(

avatar image Spittin_fire · Jul 06, 2011 at 01:09 PM 0
Share

oh yeah, and I do understand that they are 'game objects' but I want all of this I am working on to stay under one script, not make four different objects of GUITextures in to view of Unity, I want to script them into existance, I have an unnatural hunger to learn as much coding as I can before i head off to school :)

1 Reply

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

Answer by Spittin_fire · Jul 08, 2011 at 01:08 AM

 using UnityEngine;

using System.Collections;

// Use this on a guiText or guiTexture object to automatically have them // adjust their aspect ratio when the game starts.

public class GuiRatioFixer : MonoBehaviour { public float m_NativeRatio = 1.3333333333333F;

 void Start ()
 {
     float currentRatio = (float)Screen.width / (float)Screen.height;
     Vector3 scale = transform.localScale;
     scale.x *= m_NativeRatio / currentRatio;
     transform.localScale = scale;
 }
 

}

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 Spittin_fire · Jul 08, 2011 at 01:09 AM 0
Share

FOUND IT!!! $$anonymous$$WAHAHAHAHAHA

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Texture inside GUI 1 Answer

How to GUI Resize and Reposition accordingly to AR and Resolution? 0 Answers

Apply Render Texture To GUI + Transparency? 2 Answers

GuiTexture (Touch button) unfollow camera! 1 Answer

GUITexture Button? 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