Search Unity

Question ScreenPointToLocalPointInRectangle

Discussion in 'Visual Scripting' started by mickstv1972, Jan 1, 2023.

  1. mickstv1972

    mickstv1972

    Joined:
    Apr 14, 2022
    Posts:
    21
    Hi, just wondering if this unit "ScreenPointToLocalPointInRectangle" is available in Visual Scripting. Or can it be made ?

    I've had no luck finding it....
     
  2. PanthenEye

    PanthenEye

    Joined:
    Oct 14, 2013
    Posts:
    2,063
    Add RectTransformUtility in Project Settings/Visual Scripting as a new type in the Node Library, then regenerate nodes. It should come up in search after that.
     
  3. mickstv1972

    mickstv1972

    Joined:
    Apr 14, 2022
    Posts:
    21
    That worked, thanks.

    What I'm trying to do is convert some script "Virtual Cursor" into Visual Scripting.

    But being a Noob I'm not sure how to do it. Any help would be greatly appreciated.....



    public class FollowMouseForUI : MonoBehaviour
    {
    [SerializeField] Canvas myCanvas;
    private Camera cam;
    private Vector2 mousePosition;
    private Vector2 pos;

    private void Awake()
    {
    cam = Camera.main;
    }

    // Update is called once per frame
    void Update()
    {
    Vector2 mousePos = Mouse.current.position.ReadValue();
    RectTransformUtility.ScreenPointToLocalPointInRectangle(myCanvas.transform as RectTransform, mousePos, myCanvas.worldCamera, out pos);
    transform.position = myCanvas.transform.TransformPoint(pos);
    }
    }