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 Griffo · Dec 14, 2013 at 05:50 PM · guitexturegui texture

GUI Texture button child of camera

Hi,

I've got a GUI texture of a button that I have in the bottom right of the screen and I'd like to child it to my camera but when the camera moves the GUI texture button moves out of view, I'd like to have it child of the camera so I can make a prefab of the camera with the GUI texture button attached.

I've tried using Camera.main.ViewportToWorldPoint() but cannot get to see the button, only if I don't have it as child and set it's position to (0,0,0)

Can someone point me in the right direction please, thanks.

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 Tomer-Barkan · Dec 15, 2013 at 06:47 AM

GUI Texture's position is always a fraction that represents it's position relative to the screen. So if the position X is 0, it's the leftmost part, 1 is the rightmost part, and 0.5 is the middle of the screen.

Making it a child kinda breaks this, as you can see in my question here.

I ended up solving this by using sprites instead of GUI Textures. But if you want to use GUI textures, either don't make them children of anything, or make them children of an empty GameObject located in 0,0,0 and definitely don't make them children of a moving object.

You could create an empty game object, that will hold both the camera and the GUI textures, and will always remain in 0,0,0, that way you can still instantiate them both at once with a single prefab.

Edit: Any objects that you need to connect to the GUITexture objects, you can also make a child of the same empty gameobject, and then they will all be part of the same prefab.

Comment
Add comment · Show 4 · 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 Griffo · Dec 15, 2013 at 08:08 AM 0
Share

tbkn, thank you for the input, much appreciated.

Thats what I'd thought it's not advisable to do what I wanted to do.

I already have my GUI buttons child of a empty gameObject that stays a (0,0,0,) and all works fine, and also have it saved as a prefab, I also have my character who is controlled by the GUI controls saved as a prefab, so when I put my character and my GUI controls prefabs into the scene I have to make the connections again so I was looking to child the GUI controls to the character so all the connections are made and it's all saved as one prefab.

avatar image Tomer-Barkan · Dec 15, 2013 at 09:01 AM 0
Share

$$anonymous$$aking the GUI controls children does not work well with GUITexture or GUIText, because their transform works very differently than world object transform. I'd say this is not such great design on Unity's side, but that's what we have.

You could make your character prefabs under the same empty gameobject, and make them one prefab, then you wouldn't need to create the connections.

avatar image Griffo · Dec 15, 2013 at 09:28 AM 0
Share

O dear .. :), you know I never even thought of doing it the other way round, like you say parent the character to the same empty game object as the GUI controls, that works, and like you say I don't have to make the connections, please convert your last comment to an answer so I can accept it as the correct answer, thank you

avatar image Tomer-Barkan · Dec 15, 2013 at 09:33 AM 0
Share

lol, that's what I was trying to say in my original answer, but I edited anyway to make it clearer.

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

GUI Texture ontop of another GUI Texture 1 Answer

Screenshot PNG to GUITexture (NONE Texture) 0 Answers

Way to have a pause and play texture in same GUI texture? 0 Answers

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

OnGui Function help 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