Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question ScreenPointToLocalPointInRectangle

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

  1. mickstv1972

    mickstv1972

    Joined:
    Apr 14, 2022
    Posts:
    15
    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:
    1,790
    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:
    15
    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);
    }
    }