the type or namespace name "RigidBody2D" could not be found
Решил сделать 2д платформер и учусь по видосам с примерами. Обратил внимание что синтаксис скрипта c# даже не подсвечивается а потом начал получать ошибку: 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 Hero : MonoBehaviour
{
[SerializeField] private float speed = 3f;
[SerializeField] private int lives = 3;
[SerializeField] private float JumpForce = 5f;
private RigidBody2D rb;
private SpriteRenderer sprite;
private void Awake()
{
rb = GetComponent<RigidBody2D>();
sprite = GetComponentinChildren<SpriteRenderer>();
}
private void Update()
{
if (Input.GetButton("Horzintal"))
Run();
}
private void Run()
{
Vector3 dir = transform.right * Input.GetAxis("Horizontal");
transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
}
}
Ответы (1 шт):
Смотри В чём конкретно ошибка объяснить подробно не смогу, но это связано с тем, что ты не выбрал как открывать, точнее чем открывать скрипты. Вот как решить проблему:
В общём Заходишь в свой проект в Unity, в верху нажимаешь на Edit -> Preferences... . Там выбираешь External Tools и в External Script Editor выбираешь VS 2019
