Home > Software design >  Can't add Rigidbody 2D to variable
Can't add Rigidbody 2D to variable

Time:09-08

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.

CodePudding user response:

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