Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/289.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 统一跳跃功能。KeyCode工作,但CrossPlatformInputManager不工作_C#_Visual Studio_Unity3d_2d Games - Fatal编程技术网

C# 统一跳跃功能。KeyCode工作,但CrossPlatformInputManager不工作

C# 统一跳跃功能。KeyCode工作,但CrossPlatformInputManager不工作,c#,visual-studio,unity3d,2d-games,C#,Visual Studio,Unity3d,2d Games,公共类PlayerInfo:单一行为 { //移动 公共刚体2D播放器B; 公共浮点数xSpeed=10f; 私有向量2 xForce; //跳跃 公共安全部队; //地面检查 私人学校停课; 公开审查; 公共浮动校验半径; 公共层码头; //动画师 公共动画师; //启动计时器 公共文本倒计时启动; 私人浮动倒计时=4f; private bool moveBool=false; //在第一帧更新之前调用Start void Start() { playerRb=GetComponent();


公共类PlayerInfo:单一行为
{
//移动
公共刚体2D播放器B;
公共浮点数xSpeed=10f;
私有向量2 xForce;
//跳跃
公共安全部队;
//地面检查
私人学校停课;
公开审查;
公共浮动校验半径;
公共层码头;
//动画师
公共动画师;
//启动计时器
公共文本倒计时启动;
私人浮动倒计时=4f;
private bool moveBool=false;
//在第一帧更新之前调用Start
void Start()
{
playerRb=GetComponent();
animator.enabled=false;
}
无效更新()
{

如果(倒数计时)欢迎使用SO。请查看帮助中心,了解如何提问。您必须将代码复制到问题中,而不是将代码的图片复制到问题中。您的问题到底是什么?什么不符合您的要求,等等。

public class PlayerInfo : MonoBehaviour
{
    // move
    public Rigidbody2D playerRb;
    public float xSpeed = 10f;
    private Vector2 xForce;

    // Jump
    public float jumpForce;

    // Ground Check
    private bool isGrounded;
    public Transform groundCheck;
    public float checkRadius;
    public LayerMask whatIsGround;

    // Animator
    public Animator animator;

    // Start Timer
    public Text countDownStart;
    private float countDown = 4f;
    private bool moveBool = false;

    // Start is called before the first frame update
    void Start()
    {
        playerRb = GetComponent<Rigidbody2D>();
        animator.enabled = false;
    }

    void Update()
    {
        if (countDown <= 0f)
        {
            countDownStart.enabled = false;
            moveBool = true;
        }
        countDown -= Time.deltaTime;
        countDownStart.text = Math.Floor(countDown).ToString();        
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        isGrounded = Physics2D.OverlapCircle(groundCheck.position, checkRadius, whatIsGround);

        xForce = new Vector2(xSpeed * Time.deltaTime, 0);

        //playerRb.AddForce(xForce);
        if (moveBool)
        {
            playerRb.velocity = xForce.normalized * xSpeed;
            animator.enabled = true;
        }

        if (CrossPlatformInputManager.GetButtonDown("Jump"))
        {
            jump();
        }

        if (Input.GetKey(KeyCode.A))
        {
            jump();
        }
    }

    public void slide()
    {
        if (isGrounded == true)
        {
            animator.SetBool("isSliding", true);
        }
        else
        {
            animator.SetBool("isSliding", false);
        }
    }

    public void jump()
    {
        if (isGrounded == true)
        {
            playerRb.AddForce(new Vector2(0f, jumpForce), ForceMode2D.Impulse); // Impulsa eğrisine göre.   
            animator.SetBool("isJumping", true);
        }
        else
        {
            animator.SetBool("isJumping", false);
        }
    }

    private void OnDrawGizmosSelected()
    {
        Gizmos.DrawWireSphere(groundCheck.position, checkRadius);
    }
}