Unity 5.6 - "The type or namespace name `Rigidbody2d' could not be found. Are you missing an assembly reference?" when using AddComponent
I'm trying to add a Rigidbody2d component to an Object, in code, and I'm getting this error:
The type or namespace name `Rigidbody2d' could not be found. Are you missing an assembly reference?
This is my code:
Rigidbody2d myRigidbody = gameObject.AddComponent<Rigidbody2d>() as Rigidbody2d;
These are my using directives:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
I'm using Unity 5.6.1f1
Answer by Bunny83 · Mar 16, 2018 at 01:26 AM
Rigidbody2D instead of Rigidbody2d. Don't you use an IDE with intellisense / autocompletion?
Oh lord, you're right. Every thing I googled seemed to have people spelling body with a capital B. I didn't realize D needed to be capitalized, even though I've used Rigidbody2D plenty in the past.
I'm using Visual Studio Community 2017, and for some reason the (intellisense?) suddenly stopped working correctly with Unity specific things. I should probably figure out why that's not working and get it working again.
It was actually a specific script that IntelliSense wasn't working in. IntelliSense worked in all the other scripts. It was weird. So I upgraded VS 15.4.4 to 15.6.3 and it seems to be working again, now.
Thanks for the help!