Персонаж в юнити не может прыгать и менять направление

Писал с ютуба код, короче у него работает, а у меня нет. код приложу и фото.Буду благодарен за помощь, учусь пользоваться юнити, пока копипащу код, а потом пойму чо и как это едят.

Ошибка:

NullReferenceException: Object reference not set to an instance of an object
PlayerControler.Jump () (at Assets/Scripts/PlayerControler.cs:38)
PlayerControler.Update () (at Assets/Scripts/PlayerControler.cs:25)
public class PlayerControler : MonoBehaviour
{
    [SerializeField] private float speed = 3f; // Скорость прыжка.
    [SerializeField] private float jumpForce = 15f; // Сила прыжка.
    [SerializeField] private int lives = 5; // Количество жизни.

    private Rigidbody2D rb;
    private SpriteRenderer sprite;

    private void awake()
    {
        rb = GetComponent<Rigidbody2D>();
        sprite = GetComponentInChildren<SpriteRenderer>();
    }

    private void Update()
    {
        if (Input.GetButton("Horizontal"))
            Run();
        if (Input.GetButtonDown("Jump"))
            Jump();
    }

    private void Run()
    {
        Vector3 dir = transform.right * Input.GetAxis("Horizontal");

        transform.position = Vector3.MoveTowards(transform.position, transform.position + dir, speed * Time.deltaTime);
      
    }

    private void Jump()
    {
        rb.AddForce(transform.up * jumpForce, ForceMode2D.Impulse);
    }
}

введите сюда описание изображения


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

Автор решения: Nick

Попробуй переменным speed и jumpforce присвоить статус public, а не private. Как я понял (могу и ошибаться), ошибка заключается в том, что функции Run и Jump не могут получить доступ к переменным speed и jumpforce

→ Ссылка