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.
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 );
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);
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;
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);