Trouble compiling with Rigidbody2d

Hi there, I’m having trouble compiling once I added this script…

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class PlayerController : MonoBehaviour

{

Rigidbody2d rgbd;

// Start is called before the first frame update

void Start()

{

    rgbd = GetComponent<Rigidbody2d>();    

}

// Update is called once per frame

void Update()

{

   

}

}

The error message is:
Assets\Scripts\PlayerController.cs(7,5): error CS0246: The type or namespace name ‘Rigidbody2d’ could not be found (are you missing a using directive or an assembly reference?)

I think visual studio code updated last night. I wonder if a path or reference got messed up, but I don’t know where to look. Thanks!

edit: It seems to be fixed. I went back to the the “Intellisense issues” topic and the Omnisharp:select project thing from VS Code seems to have done the trick. I guess I’ll leave this up in case anyone else has the same problem.

1 Like

Hi!

Remember that C# is a case sensitive language, your code was asking for Rigidbody2d which doesn’t exists in Unity, the difference with the real name of the component is very subtle but it is enough to mark you that error. To access the component you need to ask for a Rigidbody2D, the last character, “D”, is upper case.

Your problem was solved after updating because intellense was back on track, so it catched the typo and fixed it for you.

Hope this clarify things a little.

You’re exactly right. I’m glad you pointed that out. I ended up deleting the script and creating a new one once intellisense was working again, so I never noticed that I had the typo. Thanks for the catching that and thank you for the response. I really appreciate your help.

1 Like

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms