카테고리 없음

Mouse Pointer Free Aspect에서도 동작

기억해조 2022. 12. 14. 17:56

Free Aspect에서도 동작함

 

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class InputManager : MonoBehaviour
{
    public RectTransform pointerRectTrf;
    public Canvas parentCanvas;


    //Mouse Pointer 만들기
    private void Update()
    {
        UpdateMousePos();
    }

    private void UpdateMousePos() 
    {
        Vector2 movePos;

        RectTransformUtility.ScreenPointToLocalPointInRectangle(
            parentCanvas.transform as RectTransform,
            Input.mousePosition, parentCanvas.worldCamera,
            out movePos);

        Vector3 mousePos = parentCanvas.transform.TransformPoint(movePos);

        //Set fake mouse Cursor
        pointerRectTrf.transform.position = mousePos;
    }

}

https://stackoverflow.com/questions/43802207/position-ui-to-mouse-position-make-tooltip-panel-follow-cursor

 

Position UI to mouse position (Make Tooltip panel follow cursor)

I made a tooltip panel follow the cursor with void Update () { this.transform.position = Input.mousePosition; } in the Update function. The panel "lags" behind, moving to cursor position a...

stackoverflow.com