运行时不见任何报错信息,但是却不能正常控制目标胶囊。这就很苦恼了,,或提供一点调查的方向。另外,unity有没有可以看到代码执行过程的功能?或许有助于我找到问题。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerBehavior : MonoBehaviour
{
public float moveSpeed = 10f;
public float rotateSpeed = 75f;
public float jumpVelocity = 5f;
//1
public float distanceToGround = 0.1f;
//2
public LayerMask groundLayer;
private float _vInput;
private float _hInput;
private Rigidbody _rb;
//3
private CapsuleCollider _col;
void Start()
{
_rb = GetComponent();
//4
_col = GetComponent();
}
void Update()
{
_vInput = Input.GetAxis("Vertical") * moveSpeed;
_hInput = Input.GetAxis("Horizontal") * rotateSpeed;
//5
if (IsGrounded() && Input.GetKeyDown(KeyCode.Space))
{
_rb.AddForce(Vector3.up * jumpVelocity, ForceMode.Impulse);
}
}
void FixedUpdate()
{
}
//6
private bool IsGrounded()
{
//7
Vector3 capsuleBottom = new Vector3(_col.bounds.center.x, _col.bounds.min.y, _col.bounds.center.z);
//8
var grounded = Physics.CheckCapsule(_col.bounds.center, capsuleBottom, distanceToGround, groundLayer, QueryTriggerInteraction.Ignore);
return grounded;
}
}