- Home /
Im getting this error: An object reference is required to access non-static member`UnityEngine.Component.rigidbody2D'
Hello, I have the following code within the update function (c#):
if(Input.GetKey(KeyCode.UpArrow))
{
rigidbody2D.velocity.y = speed;
}
and I am getting this error:
Assets/player.cs(16,32): error CS0120: An object reference is required to access non-static member`UnityEngine.Component.rigidbody2D'
Can anyone assist? thanks
Comment
Answer by robertbu · Mar 20, 2014 at 06:45 PM
Do you have this code inside a static function? That's likely your problem. Static functions are associated with the class not with a component on a specific game object.
Your answer
Follow this Question
Related Questions
Creating 2D art in a 3D world 3 Answers
A node in a childnode? 1 Answer
combine kinect with Gameobject! 0 Answers
Object jumps right after the attached HingeJoint2D is Enabled 0 Answers
Changing multiple toggle states. 0 Answers