I wrote in Microsoft visual studio, trying to write code to spin. I wrote “transform.rotate(0, speed, 0)”
the transform.rotate is an error. It says, "void transform.rotate(float xAngle, float yAngle, float zAngle)
Applies a rotation of zAngle degrees around the z axis…the same for x and then the same for y…then it says, "in that order. then, "an objects reference is required for the non static field, method, or property ‘transform.rotate(float, float, float)’ How do I fix this, and what does it mean? Or, at least point me to the answer.
thank you,
a rookie
I think what this means is that the script is trying to rotate something that doesn’t exist. In other words, you haven’t told unity what to apply this script to!
Here are some steps to make sure you’re setting things up properly.
First off, you reference transform.rotate… transform refers to the transform of a GameObject. You need to make sure your script is attached to a GameObject for this to do anything.
For example, create a cube object in unity, and then drag your script from your assets folder onto the components of the cube. This tells unity that that script is acting on that particular game object. Now the script will know that transform._____ is referencing that GameObject’s transform.
Next, your script needs to have some kind of way for unity to access it. The most common ones are
void Awake () {
// this happens when GameObject is created
}
void Update () {
//this is called every frame of the game by unity
}
void FixedUpdate () {
//this is called to update any physics related things. Such as movement
//and forces. Your script should probably go here if it's moving something
// that has a rigid body on it.
}
Hope that helps.
I left click(from the bottom of the screen in the assets window, then I dropped the script in my sprit (a sphere). But, I still get the error. have I missed something? @thebebinator