D
D
Dima Klepko2022-01-07 14:05:43
Unity
Dima Klepko, 2022-01-07 14:05:43

Variable type Rigidbody2D cannot be assigned to Rigidbody2D, how to solve the problem?

using UnityEngine;

public class player : MonoBehaviour
{
    public float jumpForce = 10f;

    public Rigidbody2D rb;

    void Start()
    {
       rb = GameObject.FindWithTag("player").GetComponent<Rigidbody2D>();

    }
    void Update()
    {
        if(Input.GetMouseButton(0))
        {
            rb.velocity = Vector2.up * jumpForce;
        }
    }
}

Выдает ошибку: The variable rb of player has not been assigned.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Farawa, 2022-01-07
@Farawa

Most likely the Player tag. And also give up these finds

N
Nekit Medvedev, 2022-01-10
@NIKROTOS

Do you have one player? Throw it through the unity interface (just transfer the object that has rb to the appropriate property).
If there are several, do it as a separate script or object.
Maybe your player doesn't have rb. Or there is no object with the corresponding tag at all.
You can try using new

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question