- Home /
 
C# Non-Static Member Rigidbody2D.MovePosition
I'm trying to make a script where a 2dGameobject with the script attached rotates around another 2dGameobject called RotateAroundObject and if that Gameobject isn't near the RotateAroundObject then move towards RotateAroundObject's position. But I keep getting an error saying I need an object reference for accessing a non-static member. What exactly is wrong with my code and how do I fix this error? I'm fairly certain all the parameters are correct.
 using UnityEngine;
 using System.Collections;
 
 public class RotateAround : MonoBehaviour {
     public GameObject RotateAroundObject;
     // Use this for initialization
     void Start () {
     
     }
     
     // Update is called once per frame
     void Update () {
         if(Vector3.Distance( transform.position, RotateAroundObject.transform.position) < 1)
         {
             transform.RotateAround(RotateAroundObject.transform.position, Vector3.forward, 20 * Time.deltaTime);
         }
         else if(Vector3.Distance( transform.position, RotateAroundObject.transform.position) > 1)
         {
          Rigidbody2D.MovePosition(RotateAroundObject.transform.position);
         }
     }
 }
 
 
              Answer by robertbu · Oct 16, 2014 at 05:47 AM
Line 19 should refer to 'rigidbody2D' with a lower case 'R'. Upper case 'R' is the class. Lower case 'r' is a reference to the component on this game object.
Your answer
 
             Follow this Question
Related Questions
C# Randomly Adding Elements from stringListA to stringListB 1 Answer
C# Input.GetKey("Tab") Double Tap 1 Answer
C# Adding Multiple Elements to a List on One Line 5 Answers
C# Unity 3d Don't Destroy Class On Load 1 Answer
How to dynamically change the text in Unity(Augmented Reality + NYARtoolkit(C#)) ? 0 Answers