An Object reference is required for the non static field....?

…method or property. Hey all. I have been wondering about making a system where my ‘2D’ sprite character walks up, down, left, right and so on on a grid. I have made a little script and I get the same issue after trying many different methods.

This is the part of code the error apears on:

Transform.position += Vector3.right;

Transform.position += Vector3.left;

Transform.position += Vector3.down;

Transform.position += Vector3.up;

This is the entire code:

using UnityEngine;
using System.Collections;

public class ChracterControler : MonoBehaviour {
    public float snapValue = 1;
    public float depth = 0;
   
    void Update(){

        float x, y, z;

                if (Input.GetKey ("w"))
                        Transform.position += Vector3.up;
       
               
        if (Input.GetKey ("a"))
                        Transform.position += Vector3.left;

           
        if (Input.GetKey ("d"))
                        Transform.position += Vector3.right;

               
        if (Input.GetKey ("s"))
                        Transform.position += Vector3.down;

               
        float snapInverse = 1 / snapValue;

        x = Mathf.Round(transform.position.x * snapInverse) / snapInverse;
            y = Mathf.Round(transform.position.y * snapInverse) / snapInverse;
                z = depth;





        }
}

Make the T on Transform lower case.

1 Like

I did it and it works which is awesome. However when I add the script to a gameobject it says the script does not exist. :stuck_out_tongue:

Make sure the filename matches the class name

1 Like

Fixed thanks, Does not work the way I had it in theory but I will figure that out eventually. Thank you all!