Я написал код и он выдал ошибку
ошибка: The type or namespace name 'RigidBody2D' could not be found (are you missing a using directive or an assembly reference?)
Код:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PM : MonoBehaviour
{
public float speed;
private Vector2 direction;
private RigidBody2D Rb;
void Start()
{
Rb = GetComponent<RigidBody2D>();
}
void Update()
{
direction.x = input.GetAxisRaw("Horizontal");
direction.y = input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
Rb = MovePosition(Rb.position + direction * speed * Time.fixedDeltaTime);
}
}
Ошибка указывает на то, что компилятор не может найти тип или пространство имен 'RigidBody2D', которое вы используете в своем коде.
Это происходит потому, что правильное название класса - 'Rigidbody2D' (с заглавной буквы "B" в слове "Body").
Исправьте имя класса в строке 11, заменив 'RigidBody2D' на 'Rigidbody2D':
private Rigidbody2D Rb;
После этого код должен успешно скомпилироваться.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PM : MonoBehaviour
{
public float speed;
private Vector2 direction;
private Rigidbody2D rb;
void Start()
{
rb = GetComponent<Rigidbody2D>();
}
void Update()
{
direction.x = Input.GetAxisRaw("Horizontal");
direction.y = Input.GetAxisRaw("Vertical");
}
void FixedUpdate()
{
rb.MovePosition(rb.position + direction * speed * Time.fixedDeltaTime);
}
}