Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • Help Room /
avatar image
0
Question by Rosh7 · Mar 01, 2018 at 01:02 AM · guiinput.mouseposition

Need help with gui text next to mouse

So for my script i just want to have my gui text show up right under the mouse cursor. The way I have it right now it just moves the text to the bottom right corner. My Code: messageSystem.transform.position = mainCamera.GetComponent().ScreenToViewportPoint(Input.mousePosition); message system is a Text variable and mainCamera is a Game Object.

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 Cuttlas-U · Mar 01, 2018 at 08:42 AM

hey ; u set it to mouse position ;

so u just need to create a new vector3 and modify the mouse position inside it

like this :

 Vector3 UpRightMouse = new vector3(Input.mousePosition.X +3 , Input.mousePosition.Y + 5 , Input.mousePosition.Z);


SO i changed the x and y by 3 and 5 and set it based on input mouse position ;

then u can use it in your code :

 messageSystem.transform.position = mainCamera.GetComponent().ScreenToViewportPoint(UpRightMouse );

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 Rosh7 · Mar 02, 2018 at 12:36 AM 0
Share

Hey so that didn't do it. It just has the text in the bottom right corner no matter what I add to the x and to the y.

Vector3 UpRight$$anonymous$$ouse = new Vector3(Input.mousePosition.x + 20, Input.mousePosition.y + 20, Input.mousePosition.z); messageSystem.transform.position = mainCamera.GetComponent().ScreenToViewportPoint(UpRight$$anonymous$$ouse);

avatar image Cuttlas-U Rosh7 · Mar 02, 2018 at 12:56 PM 0
Share

if its a UI text try to use "ScreenToWorldPoint"

cause its an object in the scene;

just notice using this code may need to change the "z" variable too cause it may get into below layers;

avatar image Rosh7 Cuttlas-U · Mar 06, 2018 at 12:22 AM 0
Share

Sorry for the delay, but I just tried it and it still is just putting the text in the lower left corner. Current Code:

Vector3 UpRight$$anonymous$$ouse = new Vector3(Input.mousePosition.x + 3, Input.mousePosition.y + 5, Input.mousePosition.z); messageSystem.transform.position = mainCamera.GetComponent().ScreenToViewportPoint(UpRight$$anonymous$$ouse);

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

190 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 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 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 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 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 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 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 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

Add gui over Handheld.PlayFullScreenMovie 0 Answers

UI (Canvas) element disappears when loading additive scene 1 Answer

How to make a health script for a custom health bar (In A Canvas)? 3 Answers

My GUI isn't scaling well with screen size 1 Answer

List becomes empty when accessed in another class 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