ButtonLeft和Right不会使用AxisScripts响应操作

时间:2019-04-28 21:10:56

标签: unity3d

photo 我在yt上跟随了一个教程,向我显示了此内容,但是我的左右按钮没有响应 本教程使用RIGIDBODY 2d,我使用simple,这是我的播放器脚本

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityStandardAssets.CrossPlatformInput;

public class Player : MonoBehaviour
{
    private Rigidbody rb;
    private Animator anim;
    public float moveSpeed = 5f; 
    private float dirX;
    private bool facingRight = true;
    private Vector3 localScale;



    private void Start()
    {
        GetComponent<Rigidbody>().constraints = RigidbodyConstraints.FreezeRotation;
        rb = GetComponent<Rigidbody>();
        anim = GetComponent<Animator>();
        localScale = transform.localScale;
        moveSpeed = 5f;

    }


    private void Update()
    {
        dirX = CrossPlatformInputManager.GetAxis("Horizontal") * moveSpeed;
        if (CrossPlatformInputManager.GetButtonDown("Jump") && rb.velocity.y == 0)
            rb.AddForce(Vector2.up * 700f);
        if (Mathf.Abs(dirX) > 0 && rb.velocity.y == 0)
            anim.SetBool("isRunning", true);
        else
            anim.SetBool("isRunning", false);
        if (rb.velocity.y == 0)
        {
            anim.SetBool("isJumping", false);
            anim.SetBool("isFalling", false);
        }
        if (rb.velocity.y > 0)
            anim.SetBool("isJumping", true);
        if ( rb.velocity.y < 0 )
        {
            anim.SetBool("isJumping", false);
            anim.SetBool("isFalling", true);
        }
    }
}
 我的播放器处于Blender中的3D模式下,我想进行2D游戏。我想用这个按钮控制玩家的动作,有什么主意吗?我没有任何错误

0 个答案:

没有答案