Since we don't want code cluttering up the Update() method, we'll do our layer mask calculations in a utility function and return a true or false value based on the outcome. To do so, proceed as follows:
- Add the following code to PlayerBehavior and play the scene again:
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<Rigidbody>();
// 4
_col = GetComponent<CapsuleCollider>();
}
void Update()
{
// ... No changes needed ...
}
void FixedUpdate()
...