an object reference is required to access non-static member

I know this is a frequent issue, but here’s the code:

using UnityEngine;
using System.Collections;

public class CameraMovement : MonoBehaviour {
	int CameraMovementSpeed = 2;
	// Use this for initialization
	void Start () {
	
	}

	// Update is called once per frame
	void Update () {
		Transform.Translate (0, 0, CameraMovementSpeed);
	}
}

I’m new to Unity and C#, in fact my only experience is in basic C++ programming.
I have two questions:

  • Why isn’t this working? I’m trying to mimic this javascript version: Unity 3D: Introduction to Scripting - YouTube

  • Why does it all have to be in class brackets? Can’t it look like this instead? (Here it even complains about the “int CameraMovementSpeed = 2;”)

    using UnityEngine;
    using System.Collections;

     int CameraMovementSpeed = 2;
    
     // Update is called once per frame
    
        void Update () {
     	Transform.Translate (0,0,CameraMovementSpeed);
     }
    

You must have the class declaration in C#. Javascripts are also a class derived from Monobehavior, but it is done under the hood rather than explicitly.

Your problem is on line 13. Upper case ‘Transform’ should be ‘transform’. ‘Transform’ is the class. ‘transform’ is the specific transform of the game object.