【问题标题】:C# Else confusionC# 其他混淆
【发布时间】:2020-11-09 17:54:41
【问题描述】:

所以我一直在 (else) 上出错,我不确定我做错了什么,我似乎找不到问题,请帮忙,我对编码很陌生,所以这是我到目前为止的全部代码

{
public float speed;
private Rigidbody2D myRigidbody;
private Vector3 change;
private Animator animator;

// Start is called before the first frame update
void Start()
{
    animator = GetComponent<Animator>();
    myRigidbody = GetComponent<Rigidbody2D>();
}

// Update is called once per frame
void Update()
{
    change = Vector3.zero;
    change.x = Input.GetAxisRaw("Horizontal") * Time.deltaTime * speed;
    change.y = Input.GetAxisRaw("Vertical") * Time.deltaTime * speed;
     if (change != Vector3.zero) 

        transform.Translate(new Vector3(change.x, change.y));
    MoveCharacter();
    UpdateAnimationAndMove();
}

void UpdateAnimationAndMove()
{
    {
        animator.SetFloat("moveX", change.x);
        animator.SetFloat("moveY", change.y);
        animator.SetBool("moving", true);
    } else {
        animator.SetBool("moving", false);
    }

}

void MoveCharacter()
{
    myRigidbody.MovePosition(transform.position + change.normalized * speed * Time.deltaTime);
}

}

【问题讨论】:

    标签: if-statement animation boolean character 2d


    【解决方案1】:

    你不能使用else,前面没有对应的if

    if(condition)
    {
        // IF condition is true, this gets executed
    }
    else
    {
        // ELSE this gets executed
    }
    

    【讨论】:

      猜你喜欢
      • 2010-09-14
      • 2022-10-08
      • 1970-01-01
      • 1970-01-01
      • 2013-10-18
      • 2012-05-26
      • 2012-03-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多