编程-小白
2021-11-13 17:21
采纳率: 80%
浏览 64

c#和unity关于人物跳跃问题

```

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

public class PlayerContraller : MonoBehaviour
{
private Rigidbody rBody;
private AudioSource footPlayer;
private bool isGround;
void Start()
{
rBody = GetComponent();
footPlayer = GetComponent();
}

void Update()
{
    if (Input.GetKeyDown(KeyCode.Space) && isGround==true)
    {
        rBody.AddForce(Vector3.up * 200);
    }
    float horizontal = Input.GetAxis("Horizontal");
    float vertical = Input.GetAxis("Vertical");
    if ((horizontal != 0 || vertical != 0)&&isGround==true)
    {
        if(footPlayer.isPlaying==false)
        {
            footPlayer.Play();
        }
    }
    else
    {
        footPlayer.Stop();
    }
}

private void OnCollisionEnter(Collision collision)
{
    if (collision.collider.tag=="Ground")
    {
        isGround = true;
    }
}
private void OnCollisionExit(Collision collision)
{
    if(collision.collider.tag=="Ground")
    {
        isGround = false;
    }
}

}

```哪里错了呢,他不跳哎

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

相关推荐 更多相似问题