Делаю игру-платформер на юнити, учу все по уроку У меня есть игрок и платформа, оба с коллайдерами, к игроку прикреплен скрипт:
using UnityEngine;
public class playerControler : MonoBehaviour
{
public float speed = 20f;
private Rigidbody2D rb;
private float moveX;
void Start()
{
rb = GetComponent <Rigidbody2D> ();
}
void Update()
{
moveX = Input.GetAxis ("Horizontal");
rb.MovePosition (rb.position + Vector2.right * moveX * speed * Time.deltaTime);
}
}
Но когда я запускаю игру, получаю ошибку:
MissingComponentException: There is no 'Rigidbody2D' attached to the "playerSprite" game object, but a script is trying to access it.
You probably need to add a Rigidbody2D to the game object "playerSprite". Or your script needs to check if the component is attached before using it.
UnityEngine.Rigidbody2D.get_position () (at <30c4471525994106ab1e5d6bb9a98850>:0)
playerControler.Update () (at Assets/Scripts/playerControler.cs:17)
Помогите пожалуйста, пошарил весь гугл и ничего не нашел...