Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Unity Mouse Coordinates

A topic by WayfarerGames created Aug 06, 2019 Views: 113
Viewing posts 1 to 1
Submitted(+1)

if you're using Unity and are needing to convert screen space mouse coordinates to your 64x64 render texture's space, here's a script you can use! You need to make sure it's set up properly as per the comments, but other than that it'll deal with changes in screen size too. If you really need the performance (you probably don't), you can move everything above pos = Input.mousePosition; into Awake or Start, but it will cause issues if the screen size changes mid-game

https://pastebin.com/BuAe3dRL

example usage:

[SerializeField] private GetMousePos mousePos;
[SerializeField] private Camera cam;
void Update ()
{    if (Physics.Raycast(cam.ScreenPointToRay(mousePos.pos), out var hit))
    {
        // do something
    }
}