繁体   English   中英

Unity 2D,我无法解决

[英]Unity 2D, I can not resolve it

我尝试制作平台游戏,但是当我创建秋季动画时,它在以下位置向我显示了此错误CS1026: if(Player, whatIsGround == 0){

这是代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class CharacterAnim : MonoBehaviour {

private Animator anim;

public LayerMask whatIsGround;

public float Player;


void Start(){
    anim = GetComponent<Animator>();
}

void Update(){

    if(Player, whatIsGround == 0){

        anim.SetBool("Test", true);
    } else {
        anim.SetBool("Test", false);
    }

    if(Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.LeftArrow)){
        anim.SetBool("Left", true);
    } else {
        anim.SetBool("Left", false);
    }

    if(Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.RightArrow)){
        anim.SetBool("Right", true);
    } else {
        anim.SetBool("Right", false);
    }

    if(Input.GetKeyDown(KeyCode.UpArrow)){
        anim.SetTrigger("Jump");
        }
}
}

我该如何解决?

根据Microsoft文档( 链接 ):

编译器错误CS1026

)预期

发现不完整的陈述。

您在这里有2个错误。 首先,您不能像这样将float转换为bool,然后在if结构的2条语句之间不能有','符号。

我建议将“,”替换为“ &&”或“ ||” C#运算子 ),并使用Player变量制作布尔表达式,如下所示:

  if(Player > 0 && whatIsGround == 0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM