Error CS0120, how to add an object reference?
**I'm following a tutorial, and I've run into a problem, I'll just get this error twice:
Assets/Rocks and Boulders 2/Shaders/RotateGameObject.cs(18,47): error CS0120: An object reference is required to access non-static member `UnityEngine.Transform.Rotate(UnityEngine.Vector3)'
Note that this is my first question on the forum, so I'm not to sure what information might be relevant, so I'll just copy paste all my code (which luckely isn't that much).**
using UnityEngine;
using System.Collections;
public class RotateGameObject : MonoBehaviour {
public float rot_speed_x=0;
public float rot_speed_y=0;
public float rot_speed_z=0;
public bool local=false;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void FixedUpdate () {
if (local) {
UnityEngine.Transform.Rotate(transform.up, Time.fixedDeltaTime*rot_speed_z);
} else {
transform.Rotate(Time.fixedDeltaTime*new Vector3(rot_speed_x,rot_speed_y,rot_speed_z), Space.World);
}
}
}
Answer by ZefanS · Feb 08, 2016 at 01:37 AM
As the error says, the problem is on line 18. Transform.Rotate() is a non-static method, which means it can only be performed by an instantiated object. In this particular case, this should mean you just need to change the line:
UnityEngine.Transform.Rotate(transform.up, Time.fixedDeltaTime*rot_speed_z);
to:
transform.Rotate(transform.up, Time.fixedDeltaTime*rot_speed_z);
This will make the particular transform of the gameobject this script is attached to perform the rotation.
This provides some more explanation.
Hope this helps.
Your answer
Follow this Question
Related Questions
rocks moving back and forth 0 Answers
How to massive place rocks? 0 Answers