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 paulaceccon · Jan 04, 2015 at 07:42 PM · positionfollowngui

NGUI positioning over NPC

Hi.

As the question says, I'm trying to position a NGUI object over a NPC.

This is the code that I'm using to do it:

 private GameObject CreateOrderBalloon()
     {
         GameObject balloon = GameObject.Instantiate( _orderPrefab ) as GameObject;
         balloon.transform.parent = NGUITools.FindCameraForLayer( LayerMask.NameToLayer( "GUI2D" ) ).transform.parent;
         balloon.GetComponent<GUIOrderBalloon>().SetOrder( _currentOrder );
 
         Vector3 gui2dPos = Camera.main.WorldToScreenPoint( transform.position );
         Debug.Log(transform.position);
 
         gui2dPos.x -= (Screen.width / 2.0f);
         gui2dPos.y -= (Screen.height / 2.0f);
         gui2dPos.z = 0;
 
         Debug.Log(gui2dPos);
 
         balloon.transform.position = Camera.main.ScreenToWorldPoint(gui2dPos);
         balloon.transform.localRotation = Quaternion.identity;
         balloon.transform.localScale = Vector3.one;
         
         return balloon;
     }

However, no matter what's my NPC position, the balloon is always instantiated at Vector3.zero.

For example, this is what the Debug.Log prints:

Debug.Log(transform.position): -4.5, 0.0, 0.0

Debug.Log(gui2dPos): -133.4, 0.0, 0.0

And that is the position of the instantiated NGUI balloon:

P: 0, 0, 0

R: 0, 0, 0

S: 1, 1, 1

Here is the whole scene:

alt text

alt text

As can be seen, the ballon is in the middle of the scene, not in the same position of the NPC at the stall. I don't know what is wrong. I've been struggling with this problem for months now. :S

Thank you.

PS: As an alternative, I created a UIGrid and added each item there with the following code:

     private GameObject CreateOrderBalloon()
     {
         GameObject balloon = GameObject.Instantiate( _orderPrefab ) as GameObject;
         balloon.GetComponent<GUIOrderBalloon>().SetOrder( _currentOrder );
 
         UIGrid ordersGrid = GameObject.Find("Orders").GetComponent<UIGrid>();
         ordersGrid.AddChild( balloon.transform );
         ordersGrid.Reposition();
 
         balloon.transform.localScale = Vector3.one;
         balloon.transform.localPosition = Vector3.zero;
         balloon.transform.localRotation = Quaternion.identity;
 
         return balloon;
     }

This worked properly. So, I don't think I changing these items positioning somewhere else after the Debug.Log.

captura-de-tela-2015-03-13-as-103814.png (17.3 kB)
captura de tela 2015-01-04 às 17.28.21.png (115.5 kB)
Comment
Add comment · Show 1
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 paulaceccon · Mar 13, 2015 at 01:40 PM 0
Share

After the debugs:

alt text

captura-de-tela-2015-03-13-as-103935.png (53.8 kB)

0 Replies

· Add your reply
  • Sort: 

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

25 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Camera rotation around player while following. 6 Answers

Object following other object (Parent-like) 2 Answers

Following mouse 2 Answers

Camera position not updating 1 Answer

can i let the sphere follow a point(x.y. or.z) on plane? 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