- Home /
I can't use Rigidbody2D in my scripts, I can't find rigidbody2d in my script
I must use
private RigidBody2D rb2d;
I added Rigidbody2D and the script as a component to the player but it doesn't find it in the script.
,
You showed only a small portion of yours script. Do you actually have the line:
using UnityEngine;
at the top of your script? The intellisense of visual studio is really tolerant when having errors in your script, however at some degree it just isn't able to figure out what you're doing there. $$anonymous$$ake sure when you temporarily remove your variable that the script actually compiles in Unity without any errors. If VS still does not auto complete it, again make sure the script doesn't contain any errors, close Visual Studio and restart it.
Oh, and you should post code snippets or scripts as text and mark it as code. Images are bad for several reasons. In this case posting the image additionally to show the auto complete failure is ok, but as i mentioned we don't have the "full picture" (in the sense of content, not in the sense of an image).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Player : $$anonymous$$onoBehaviour {
public float speed = 50f;
public float jumppower = 150f;
public bool grounded;
private Rigidbody2D rb2d;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
}
this is my script if it helps you
Answer by JavierRuidoRosa · Jul 09, 2018 at 04:51 PM
Maybe it doesn't find the reference because you misspelled it: it's Rigidbody2D, with the b in lower case.
Then maybe it's because Visual Studio doesn't recognize your script as part of the Unity Project.
Can you tell me if, in between the code and the script name above it, you see a little box with "$$anonymous$$iscellaneous files" written in it?
If so, we can assume it's an autocompletion error, and you could read this post to find the most suitable answer to your problem.
Answer by odushev · May 25, 2019 at 01:56 PM
"B" must be not capital letter Rigid*Body2D - fault Rigidb*ody2D - true
,"B" must be not capital letter Rigid*B*ody2D - fault Rigid*b*ody2D - true
Answer by EternalClickbait · May 25, 2019 at 11:22 AM
Have you opened the C# project/solution created by unity (Either by going to the project directory or by clicking on Assets > C# Project in the Unity editor). If so, Ensure that you have using UnityEngine;
At the top of the code.