'Converting Vector2 to Vector2Int

I'm trying to convert Vector2 to Vector2Int, since that's what I'm using as a cursor in my game. I want it to snap onto pixels instead of freely move around like it's doing now, I have no idea how to convert the current Vector2, so perhaps someone could hint at what to do, or just tell me. I keep getting errors when I try it.

public RectTransform rect;

private Canvas myCanvas;

void Awake()
{
    this.myCanvas = base.GetComponent<Canvas>();
}

// Update is called once per frame
void Update()
{
    Vector2Int pos;
    RectTransformUtility.ScreenPointToLocalPointInRectangle(myCanvas.transform as RectTransform, Input.mousePosition, myCanvas.worldCamera, out pos);
    rect.position = myCanvas.transform.TransformPoint(pos);
}

If someone could help me that would be nice! I've been stuck on this for a good while now.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source