Rotating a light using the 'A' and 'D' buttons

Hi guys, I wrote a script to make the my light follow the camera’s position and another one to make the light rotate around the Y axis, for some reason I get this massage :

**

[quote]**
Assets/Standard Assets/Scripts/Light Rotation.js(5,11): BCE0020: An instance of type ‘UnityEngine.Transform’ is required to access non static member ‘Rotate’.
**[/quote]
**

here’s the light rotate script and the light follow script :

Follow :

var target : Transform;

function Update () {

               transform.LookAt(target);
			     
         }

Rotate :

var amount = 2;

function Update () {

Transform.Rotate(0,Input.GetAxis("Horizontal")*amount,0);

}

Everything works fine besides the actual rotation script because of the error massage, any clue ?

Thanks in advance, Robby …

In your second script, you’re using a capital T

Transform.Rotate()

Use lowercase

transform.Rotate()

Oops :shock: didn’t expect to miss that one :smile:

Your second script also relies on Update being a set rate. If you don’t factor Time.deltaTime into that equation, you will have the rotation happen at different rates on different machines, possibly even fluctuating rates on the same machine if the FPS changes a lot.

Heres how to factor that in

var amount = 2; // This is the amount you want to rotate each second in this case.

function Update () 
{
  transform.Rotate(0, Input.GetAxis("Horizontal") * amount * Time.deltaTime, 0); 
}

Time.deltaTime returns a float value equal to the time in seconds it too to complete the previous frame, and by multiplying your movement amount by this, you will get an even amount of rotation each frame.

Exactly… With Time.deltaTime you actually say move/rotate some amount per second rather than per frame…