-1

I want to make a text that appears next to the mouse button, where i click on a button. So i have a huge button, and i want that text to appear next to the mouse/touch screen where i clicked. How can i do it?

I'am new in this section so please write it down easily for me! And if someone could help with the animation of this text as well, to pop up then move up and dissappear just when i click!

Something is bad with my text so the site don't let me post it, so i'll try to put something else here, hopefully it'll let me post it finally.! Thanks a lot!

1
  • This question is surely about c#, not the deprecated js-like language unityscript.
    – Ruzihm
    Commented Apr 6, 2021 at 21:15

1 Answer 1

0

You should use Input.mousePosition. As the documentation says, the origin (0,0) is on bottom left corner and for get topright corner you should use (Screen.width, Screen.height).

For 2d Got mouse position with:

Vector3 mousePos = Input.mousePosition;

For 3dWorld use:

Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition)

Apply this position to your text object adding some offset:

myText.transform.position = mousePos + offSetVector;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.