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);
}
}
}