An object reference is required to access non-static member 'UVController.Move(UnityEngine.Vector3)'

I am building a simple car racing platforming game with Unity and have hit a big error that could effect the progress of the game. This problem completely stumped me…

My PlayerController script is refusing to listen to my UVController script without a reference regarding Move.

using UnityEngine;
using System.Collections;

[RequireComponent(typeof(BoxCollider2D))]
public class UVController : MonoBehaviour {

    const float hitbox = 0.015f;
    public int horizontalRayCount = 4;
    public int verticalRayCount = 4;
   
    public static UVController Instance {get; private set;}
       
    void Awake(){
        Instance=this;
    }
           
    float horizontalRaySpacing;
    float verticalRaySpacing;
   
    BoxCollider2D collision;
    FNaW raycastOrigins;
   
    // Use this for initialization
    void Start () {
        collision = GetComponent<BoxCollider2D> ();
        fx9750gii();
       
    }
   
    void Update() {
        UpdateFNaW ();
        fx9750gii ();
   
        for (int i = 0; i < verticalRayCount; i++) {
            Debug.DrawRay(raycastOrigins.bottomLeft + Vector2.right * verticalRaySpacing * i, Vector2.up * -2, Color.red);
        }
    }
   
    struct FNaW {
        public Vector2 topLeft, topRight;
        public Vector2 bottomLeft, bottomRight;
   
    }
   
    public void Move(Vector3 velocity) {
        //Instance=this;
        transform.Translate (velocity);
    }
   
    // Update is called once per frame
    void UpdateFNaW () {
        Bounds bounds = collision.bounds;
        bounds.Expand (hitbox * -2);
       
        raycastOrigins.bottomLeft = new Vector2 (bounds.min.x, bounds.min.y);
        raycastOrigins.bottomRight = new Vector2 (bounds.max.x, bounds.min.y);
        raycastOrigins.topLeft = new Vector2 (bounds.min.x, bounds.max.y);
        raycastOrigins.topRight = new Vector2 (bounds.max.x, bounds.max.y);
    }
   
    void fx9750gii() {
        Bounds bounds = collision.bounds;
        bounds.Expand (hitbox * -2);
       
        horizontalRayCount = Mathf.Clamp (horizontalRayCount, 2, int.MaxValue);
        verticalRayCount = Mathf.Clamp (verticalRayCount, 2, int.MaxValue);
       
        horizontalRaySpacing = bounds.size.y / (horizontalRayCount - 1);
        verticalRaySpacing = bounds.size.x / (verticalRayCount - 1);
    }
}
using UnityEngine;
using System.Collections;

[RequireComponent (typeof(UVController))]
public class PlayerController : MonoBehaviour {

    public float speed = 15.0f;
   
    UVController sandstorm;
    GameObject objectReference;
   
    //UVController.Move F4 = objectReference.Getcomponent<Move>();
   
    float gravity = -20;
    Vector3 velocity;
   
    float xmin = -5;
    float xmax = 5;

    void Start() {
        sandstorm = GetComponent<UVController> ();
        }
    // Update is called once per frame
       
    void Update () {
        //velocity.x = input.x * movespeed;
        velocity.y += gravity * Time.deltaTime;
        UVController.Move (velocity * Time.deltaTime);
   
        //if (Input.GetKey(KeyCode.LeftArrow)){
        //    transform.position += Vector3.left * speed * Time.deltaTime;
        //}
        //else if (Input.GetKey(KeyCode.RightArrow)){
        //    transform.position += Vector3.right * speed * Time.deltaTime;
        //}
    }
    //restrict the player to the gamespace
    //float newX = Mathf.Clamp(transform.position.x, xmin, xmax);
    //transform.position = new Vector3(newX, transform.position.y, transform.position.z);
}

What am I missing? Any help would be appreciated…

Line 28

UVController.Move (velocity * Time.deltaTime);

is trying to call a static method

sandstorm.Move (velocity * Time.deltaTime);

should fix the problem

1 Like

If you’re trying to use your semi-singleton property then you just forgot to reference it

UVController.Instance.Move(....);

but if you want to use that why are you setting up a reference to it with sandstorm in the first place?

You don’t really need in UVController this code:

public static UVController Instance {get; private set;}

In PlayerController, sandstorm is correctly initialized in Start function.
In Update just call Move like that:

sandstorm.Move (velocity * Time.deltaTime);


Game Rules
Unified Visual Scripting Asset with rules engine