Unity移动面板效果

public class MovePanel : MonoBehaviour
{
    private bool m_IsOn;
    private Transform m_Begin;
    private float m_Timer ;
    private void Start()
    {
        m_Begin = transform;
    }
    public void Moved(bool isOn)
    {
        m_IsOn = isOn;
        m_Timer = 2f;
    }
    private void MoveRight()
    {
        transform.GetComponent<RectTransform>().Translate(Vector3.right * Time.deltaTime * 300f);
    }
    private void MoveLeft()
    {
        transform.GetComponent<RectTransform>().Translate(Vector3.left * Time.deltaTime * 300f);
    }
    public void Update()
    {
        if (m_Timer > 0)
        {
            m_Timer -= Time.deltaTime;
            if (m_IsOn)
            {
                MoveLeft();
            }
            else
            {
                MoveRight();
            }
        }
    }
}

代码挂在面板上,然后注册事件就可以使用了,不懂再问我

发布了58 篇原创文章 · 获赞 3 · 访问量 1945

猜你喜欢

转载自blog.csdn.net/qq_34343249/article/details/104999697