C# 事件触发器的两个按钮

C# 事件触发器的两个按钮,c#,unity3d,2d,C#,Unity3d,2d,我想为“向左移动”和“向右移动”2D动画创建按钮(两个按钮:按钮左和按钮右) 我的c#脚本是: private bool moveLeft; private bool moveRight; Animator animator; float forwardSpeed = 10f; // Use this for initialization void Start () { animator = this.GetComponent<Ani

我想为“向左移动”和“向右移动”2D动画创建按钮(两个按钮:按钮左和按钮右)

我的c#脚本是:

private bool moveLeft;
    private bool moveRight;
    Animator animator;
    float forwardSpeed = 10f;
    // Use this for initialization
    void Start () {
        animator = this.GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update () {    
        if (moveLeft == true) {
            this.GetComponent<Rigidbody2D> ().AddForce (Vector2.left * forwardSpeed);
            animator.SetInteger ("Direction", 2);
        }
        if (moveLeft == false) {
            this.GetComponent<Rigidbody2D> ().AddForce (Vector2.right * forwardSpeed);
            animator.SetInteger ("Direction", 4);
        }
    }
    public void MoveMeLeft()
    {
        moveLeft = true;
    }
    public void StopMeLeft ()
    {
        moveLeft = false;
    }
}
private bool左移;
私有产权;
动画师;
浮动前进速度=10f;
//用于初始化
无效开始(){
animator=this.GetComponent();
}
//每帧调用一次更新
无效更新(){
if(moveLeft==true){
this.GetComponent().AddForce(Vector2.left*forwardSpeed);
animator.SetInteger(“方向”,2);
}
if(moveLeft==false){
this.GetComponent().AddForce(Vector2.right*forwardSpeed);
animator.SetInteger(“方向”,4);
}
}
公共void MoveMeLeft()
{
moveLeft=true;
}
公共无效StopMeLeft()
{
moveLeft=false;
}
}
*


所以它会触发事件,也会触发指针向下,但当指针向上时不会返回指针向上

在何处调用
MoveMeLeft
StopMeLeft
确保位置在任何动画中都没有更改,因为您在代码中更改位置(通过刚体)可能会显示您在统一中设置PointerDown和PointerUp的位置。