Can't add Rigidbody 2D to variable

Viewed 61

Screenshot of the inspector in the Unity Game Engine.

A stop sign appears instead of the cursor when I drag Rigidbody 2D over the rb slot. I have tried using a normal Rigidbody but to no avail.

1 Answers

C# script code changed to Rigidbody 2D.

as shown in the code below.

 using UnityEngine;


  public class characterController : MonoBehaviour 
{ 
    public Rigidbody2D rb;

    void Start()
   {
        rb = GetComponent<Rigidbody2D>();
   }



void Update()
{
    if (Input.GetKeyDown(KeyCode.Space))
    {
        rb.AddForce(Vector2.up * 500);
    }
  }
}

hope it helps.

Related