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 Jordi · Oct 13, 2010 at 06:12 PM · worldtoscreenpoint

Camera Relative Screen Pixel-coordinates

I've been trying to set up a Domino-Line (parent object) with 5 Dominos in it (Children). When mousing over the Domino-Line, I want two UI-elements to show up: A '-' sign behind the first domino in line, and a '+' behind the last in line.

However, when trying to use WorldToScreenPoint, the UI-elements get placed all wrong, to the left of the entire line above eachother.

So how would I fix this?

EDIT: Here's part of the code, the OnGUI function

void OnGUI() { if (playScript.gamePlays == false) { if (mouseOver == true) {

         Vector3 screenPosBegin = Camera.main.WorldToScreenPoint(transform.TransformPoint(firstStone.transform.localPosition));
         Vector3 screenPosEnd = Camera.main.WorldToScreenPoint(transform.TransformPoint(lastStone.transform.localPosition));

         if (amountOfStones > minStones) {
             if (GUI.Button(new Rect(screenPosBegin.x, Camera.main.pixelHeight - screenPosBegin.y, 50 * (1.1f - (screenPosBegin.z/20)), 50 * (1.1f - (screenPosBegin.z/20))), detractStoneTex)) {
                 amountOfStones--;
                 Destroy(lastStone);

                 touchBox.size = new Vector3( (amountOfStones * 0.5f) - 0.5f, 0.6f, 0.4f);
                 touchBox.center = new Vector3( touchBox.size.x/2, 0, 0);

             }
         }


         if (amountOfStones < maxStones) {
             if (GUI.Button(new Rect(screenPosEnd.x, Camera.main.pixelHeight - screenPosEnd.y, 50 * (1.1f - (screenPosBegin.z/20)), 50 * (1.1f - (screenPosBegin.z/20))), addStoneTex)) {
                 amountOfStones++;
                 GameObject newStone = Instantiate( Resources.Load("Domino"), Vector3.zero, Quaternion.identity) as GameObject;
                 newStone.transform.parent = transform;
                 newStone.transform.localPosition = new Vector3((amountOfStones * 0.5f) - 0.5f, 0, 0);
                 newStone.transform.localRotation = Quaternion.identity;


                 touchBox.size = new Vector3( (amountOfStones * 0.5f) - 0.5f, 0.6f, 0.4f);
                 touchBox.center = new Vector3( touchBox.size.x/2, 0, 0);
             }
         }
     }
 }


}

Right now I've made it to look -sorta- ok, by subtracting the height from it.

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 skovacs1 · Oct 13, 2010 at 06:15 PM 0
Share

Could you post some code so that we can see what might be wrong?

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

No one has followed this question yet.

Related Questions

GUIButtons Follow different GameObjects?? 1 Answer

Keeping a label fixed with WorldToScreenPoint 0 Answers

Projecting a rectangle into screen space 3 Answers

Cinemachine not working with my Movement Script 0 Answers

drawings secondary cameras in specifics places 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