Question by
themightybeef · Sep 20, 2015 at 07:47 AM ·
error message
Error CS 0120: an object reference is required to access non-static member 'UnityEngine.Transform.Rotate(UnityEngine.vector3)'
I am a beginner in scripting and was following a tutorial on how to add controller support to a VR game in unity. when trying to enter playmode I get this compiler error (the title of my question). This is the script :
using UnityEngine;
using System.Collections;
public class testcontrol : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.GetButtonDown ("fire1")) {
Transform.Rotate(Transform.rotation.eulerAngles + new Vector3 (0f, 0.1f, 0f));
}
float h = Input.GetAxis ("Horizontal");
float v = Input.GetAxis ("Vertical");
transform.position += new Vector3 (h * 0.1f, v * 0.1f, 0f);
}
}
Any help or advice is much appreciated.
Comment
Answer by Xarbrough · Sep 20, 2015 at 07:49 AM
Line 15: you need an object reference to the Transform component of your current GameObject. Just spell transform.Rotate(...) with a lowercase 't'. The "transform" property does a GetComponent() internally to retrieve a reference to the Transform component. The uppercase "Transform" is merely a class or so-called "type", which can have static functions, which work without object instances, but Rotate does need an instance to rotate.