Я пытаюсь настроить воспроизведение с помощью скрипта Unity из видео, которое я смотрю. в настоящее время я получаю сообщение об ошибке
"Не удалось найти тип имени пространства имен 'RigidBody2D'"
У меня есть RigidBody2D, прикрепленный к моему спрайту и I ' Я довольно растерялся, что делать дальше. вот моя треска любая помощь будет принята с благодарностью!
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[RequireComponent(typeof(RigidBody2D))]
// this makes sure if a rigid body doesnt exist in the player it will add one
public class playermovement : MonoBehaviour
{
public RigidBody2D playerRigidBody;
public float moveSpeed = 1f;
public void Awake()
{
playerRigidBody = GetComponent<RigidBody2D>();
}
private void FixedUpdate()
{
if(playerRigidBody != null)
{
ApplyInput();
}
else
{
Debug.LogWarning("rigid body not attached to player" +GameObject.name);
}
}
//Chek to see if any buttions are pushed down and if so perform any relivent action
public void ApplyInput()
{
float HorizontalInput = Input.GetAxis("Horizontal");
float VerticalInput = Input.GetAxis("Vertical");
float HorizontalForce = HorizontalInput * moveSpeed * Time.deltaTime;
Vector2 force = new Vector2(HorizontalForce,0);
playerRigidBody.AddForce(force);
}
}