I'm trying to make a cursor with limited range.

The title says it all. I need to make my cursor be limited to a certain range around a gameObject.

Apparently, Unity can’t make the literal mouse cursor be restrained to an area (only to being stuck to the middle of the screen), so I tried making a gameObject that would always be at mouse position, but that won’t work at all.

void Update()
    {
        transform.position = Input.mousePosition;
    }

I’ve tried ScreenToWorldPoint too, but that won’t work either.

public Camera cam;

    void Start()
    {

    }

    void Update()
    {
        transform.position = cam.ScreenToWorldPoint(Input.mousePosition);
    }

Besides the cursor needing to follow the mouse, there’s also the limited range factor. I have a script I’ve used for some other stuff that I’m trying to apply to the cursor but haven’t yet.

public float radius = 0f; // Maximum distance.
  public GameObject bound; // Object this one is bound to.
  float distance = 0f; // Actual distance.

    void Start()
    {

    }

    void Update()
    {
        distance = Vector2.Distance(transform.position, bound.transform.position);

        if(distance > radius)
        {
          transform.position = (transform.position - bound.transform.position).normalized * radius + bound.transform.position;
        }
    }

Ok, so, I figured the first part (it had something to do with the z axis of transform) but the restrain part still isn’t working :frowning: