Пересечения с объектом при использовании функции Raycast пишет , что не может найти Ground Layer. И не происходит прижок.Вот код :

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

public class PlayerController : MonoBehaviour

private Animator animator;
private Rigidbody rigidbody;
public float moveSpeed = 5.0f;
private CharacterController controller;
public Transform groundCheckerTransform;
public LayerMask groundLayer;
public float jumpForce = 2f;
// Start is called before the first frame update 
void Start()
{
    rigidbody = GetComponent<Rigidbody>();
    controller = GetComponent<CharacterController>();
    Cursor.lockState = CursorLockMode.Locked;
    Cursor.visible = false;
    animator = GetComponent<Animator>();
}

// Update is called once per frame 
void Update()
{
    float horizontalInput = Input.GetAxis("Horizontal");
    float verticalInput = Input.GetAxis("Vertical");

    Vector3 moveDirection = transform.forward * verticalInput + transform.right * 
    horizontalInput;
    moveDirection.y -= 9.81f * Time.deltaTime;
    animator.SetFloat("speed", Vector3.ClampMagnitude(moveDirection, 1).magnitude);
    controller.Move(motion: moveDirection * moveSpeed * Time.deltaTime);
    if (Input.GetKeyDown(KeyCode.Space))
    {
        Debug.Log("Clicked jump");
        Jump();
    }
}

void Jump()
{
   RaycastHit hit;
    if (Physics.Raycast(groundCheckerTransform.position, Vector3.down, 10f, groundLayer))
    {
        rigidbody.AddForce(Vector3.up * jumpForce, ForceMode.Impulse);
    }
    else
    {
        Debug.Log("Did not find ground layer");
    }
}

}


Ответы (0 шт):