If statement C#其他混淆
所以我一直在(else)上出错,我不确定我做错了什么,我似乎找不到问题所在,请帮助,我对编码很陌生,所以这里是我到目前为止的全部代码If statement C#其他混淆,if-statement,animation,boolean,character,2d,If Statement,Animation,Boolean,Character,2d,所以我一直在(else)上出错,我不确定我做错了什么,我似乎找不到问题所在,请帮助,我对编码很陌生,所以这里是我到目前为止的全部代码 { public float speed; private Rigidbody2D myRigidbody; private Vector3 change; private Animator animator; // Start is called before the first frame update void Start() { animator
{
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);
}
{
公众浮标速度;
私人刚体;
私人矢量3变化;
私人动画师;
//在第一帧更新之前调用Start
void Start()
{
animator=GetComponent();
myRigidbody=GetComponent();
}
//每帧调用一次更新
无效更新()
{
变化=矢量3.0;
change.x=Input.GetAxisRaw(“水平”)*Time.deltaTime*速度;
change.y=Input.GetAxisRaw(“垂直”)*Time.deltaTime*速度;
如果(更改!=Vector3.zero)
transform.Translate(新向量3(change.x,change.y));
MoveCharacter();
UpdateAnimationAndMove();
}
void UpdateAnimationAndMove()
{
{
SetFloat(“moveX”,change.x);
SetFloat(“moveY”,change.y);
动画师.SetBool(“移动”,真);
}否则{
animator.SetBool(“移动”,false);
}
}
void MoveCharacter()
{
myRigidbody.MovePosition(transform.position+change.normalized*speed*Time.deltaTime);
}
}如果前面没有相应的
if
,则不能使用else
if(condition)
{
// IF condition is true, this gets executed
}
else
{
// ELSE this gets executed
}