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);
}
}
}