unity 鼠标移入弹出UI

外部调用 show 和Hide方法

using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class ShowInfo : MonoBehaviour {

    private bool _isshowing = false;
    public Canvas Canvas;

    // Use this for initialization
    void Start()
    {
        Hide();
    }

    // Update is called once per frame
    void Update()
    {

    }
    public void Hide()
    {
        transform.DOScale(Vector3.zero, 0.3f);
        _isshowing = false;
    }

    public void Show()
    {
        transform.DOScale(Vector3.one, 0.3f);
        _isshowing = true;
    }
    void FixedUpdate()
    {
        if (_isshowing)
        {
            Vector2 localPoint = Input.mousePosition - new Vector3(Screen.width * 0.5f, Screen.height * 0.5f);
            Vector3 pos = (localPoint / Canvas.transform.localScale.x);
            pos.x += 10f;
            transform.DOLocalMove(pos, 0.01f);
        }
    }
}


你可能感兴趣的:(UNITY)