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 Hydropulse17 · Jul 13, 2014 at 02:13 AM · javascriptguitextureremotepixelinset

Repositioning remote GUI Texture

So that it will be viewed in any resolution, I want to move my Speedometer GUI Texture to the bottom left of the screen. My idea was to use pixleInset. Well, this worked:

 var divideX : float = -2.03;
 var divideY : float = -2.04;
 
 function Update() {
     
         guiTexture.pixelInset = Rect (Screen.width/divideX, Screen.height/divideY, 256, 256);
 }

That script can be attached to any GUI Texture and edited in the inspector to compensate for multiple HUD elements. So that's probably the best way to do it, but for my first attempt, I was trying to reposition it remotely from the control script which housed the speed variable and switched the textures to compensate for how fast the player was going, like a speedometer should. The GUI texture game object was called GaugeGUI, and I defined a variable to represent it; var GaugeGUI : GameObject; which I assigned with .Find in the start function. then I tried to do this:

 function Update() {
     
         GaugeGUI.pixelInset = Rect (Screen.width/divideX, Screen.height/divideY, 256, 256);
 }

It returned an error saying that .pixelInset is not a member of GameObject. Which makes sense, but is there a way to remotely access that GUI texture? I ask after already finding a better method simply for the sake of being a well rounded programmer.

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
0

Answer by SomethingStrangeStudios · Jul 13, 2014 at 04:24 AM

You can pass a variable into a function from the camera using "WorldtoViewPortPoint", that way you can position the gui texture in relation to the camera not the world.

http://docs.unity3d.com/ScriptReference/Camera.WorldToViewportPoint.html

 var viewPos : Vector3 = camera.WorldToViewportPoint (MYtarget.position);

Thats passing your view from a camera to an object/texture and you can move the texture from the textures script.

this is using

 var viewPosX:float=camera.WorldToViewportPoint(Mytarget.position.x);
 MyGUITexture.SendMessage(myFunction,viewPosX);


on your camera, to your "myFunction" function in the Guitextures script.


as well as that you can handle the gui inside the camera using a translate method and calling your GUITexture in the cameras script.

 MyGUITexture.transform.translate=Vector2(viewPosX,0)


PS. Also i've looked up pixel inset and it should be used with a guitexture, (i've never used this before) but assuming that and that you were using a guitexture why did it refer to it as a gameobject?

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

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

How can i show the texture in the array? 2 Answers

DrawTexture GUI iPhone 1 Answer

How do I change the texture of a Raw image? 0 Answers

Setting Scroll View Width GUILayout 1 Answer

pixelInset to Move a GUITexture C# 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