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
3
Question by Diekeke · Jun 26, 2013 at 11:38 PM · cameraguigameobjecttransformscreen

Keep GameObject on a corner of the screen

 var guiCam : GameObject;
 var targetPos : Vector3;
 
 function Update () 
 {
     transform.localPosition = guiCam.camera.ScreenToViewportPoint(targetPos);
 } 

Hi, well, the thing is that I have this script attached to the gameobject that I want to keep on the corner independently of the screen resolution, and the gameobject is a child of my GUI camera (which renders all of my gui stuff), but I can't get it to work, I adjust the desire position and everything but when I go fullscreen it goes out of the screen, so it's basically not working. I don't know what I'm doing wrong. Please help! 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 Eric5h5 · Jun 27, 2013 at 01:06 AM 0
Share

Why are you using ScreenToViewportPoint? GameObjects don't use viewport space.

avatar image Diekeke · Jun 27, 2013 at 01:11 AM 0
Share

Because I saw it in another answer and I really don't know ANYTHING about all those camera functions, plus I already tried with the others but I don't quite know how to used them. I would really apreciate the right way to do it or maybe an example. Thanks.

avatar image robertbu · Jun 27, 2013 at 01:44 AM 0
Share

What kind of a game object is this script attached to? A plane? A GUITexture? Some other game object? Are you trying to get the object exactly in a corner or at an edge, or can you live with approximately in the corner/edge?

avatar image Diekeke · Jun 27, 2013 at 01:55 AM 0
Share

It's a 3D object from blender, it's the hunger meter, I need it to be right behind the life meter which is a heart, and the hunger meter is a circular object surrounding it, the life meter is a GUITexture so it's always at the corner where it is supposed to be, but the hunger meter is not so it changes position with different resolutions

1 Reply

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

Answer by robertbu · Jun 27, 2013 at 02:10 AM

You have an issue that is solvable by using blender or by using an empty game object. That is, you need the pivot/anchor/origin of the hunger meter to be in the corner you want to anchor. You can do this by moving the pivot to the corner in blender, or by placing an empty game object in the corner and making the hunger meter a child of the empty game object. Then you can use Camera.ViewportToWorldPoint() to position the hunger meter. Note you will need to specify a distance in front of the camera to position the object.

 var v3Pos = Vector3(0.0, 1.0, 0.25);
 transform.position = gui.camera.ViewportToWorldPoint(v3Pos);

The above lines will place the object in the upper left corner of the screen 0.25 units in front of the camera.

Comment
Add comment · Show 11 · 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 Diekeke · Jun 27, 2013 at 02:19 AM 0
Share

Wow! I'll definately try that! I'll let you know by tomorrow :)

avatar image Diekeke · Jun 27, 2013 at 08:48 PM 0
Share

Oh my god it totally works! Thank you so much!

avatar image Diekeke · Jun 27, 2013 at 09:11 PM 0
Share

And if I wanted to do the same thing but with the health meter (GUITexture) so there wouldn't be any other problem?

avatar image robertbu · Jun 27, 2013 at 11:55 PM 0
Share

Actually GUITextues use Viewport coordinates already, so you can set the position directly and expect it to change for different screen resolutions/ratios.

avatar image Diekeke · Jun 28, 2013 at 04:51 PM 0
Share

Yeah, but is not 100% accurate, in some resolutions everything's okay, but in others, the H.$$anonymous$$. is a little bit to the right according to the L.$$anonymous$$., and in others, the L.$$anonymous$$. is offset as well, so it doesn't looks so good because they have to be perfectly aligned. Is this something that can be fixed, or do I just have to live with it?

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

Collision delete 1 Answer

Set Game Object Position to Sides of a Camera 1 Answer

Game Texture - Always Face Camera 1 Answer

Rotate camera around gameobject 1 Answer

I am getting an error and cant figure out why, Help please? 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