#attaching a hitbox to the mouse

1 messages · Page 1 of 1 (latest)

north mesa
#

So I am trying to attach a hitbox to a mouse which I did like this:

public class MenuCursor : MonoBehaviour
{
    void Update()
    {
        Vector2 mousePos = Input.mousePosition;
        Vector2 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
        transform.position = worldPos;
    }
}

But this causes extreme lag. How the hell do I do this without the lag?

hallow barn
#

If you have many objects in the scene camera.main can cause lag because every time you call it it searches for the camera iterating through all scene objects. Therefore, try to set up camera in the inspector and use this value instead of camera.main

north mesa
north mesa
#

update: only lags in the editor for some reason?