Continuously Rotating Script?

Hi, I just needed the code to make a GameObject continuously rotate around on it’s y axis throughout the whole game (preferably every 5-6 seconds is will reach 360 Degrees and start again if you know what I mean). Thanks, Dean.

i'm also looking for this, but i also want to move the objects from left to right, i'm using three rocks and i want it them to spin and move from left to right, i hope you can understand, i can't explain more b/c my English is so bad, Thank you in advance.

–

3 Answers

3

That’s really easy:

// Unityscript
 var rotationsPerMinute : float = 10.0;
    function Update()
    {
        transform.Rotate(0,6.0*rotationsPerMinute*Time.deltaTime,0);
    }
// C#
public float rotationsPerMinute = 10f;
void Update()
{
    transform.Rotate(0, 6f * rotationsPerMinute * Time.deltaTime, 0f);
}

what if we do not want to put it in the update function? I mean, i just wanna call the function once and it should continuously rotate it.

–

@idiot333 you can then in the Start() function set the torque to a rigidbody without it having angular drag: rigidbody2D.AddTorque(20);

–

Thank you for this although I believe that there are some errors in the syntax but I could be because of different versions.

–

@Perch-Garson this question and answer is 13 years old. The code was Unityscript (a javascript like .Net language) which isn't supported anymore for years now.

–

Yes, This was exactly what I was looking for, I’m a beginner with Unity so it all seems pretty hard, thanks!

i’m also looking for this, but i also want to move the objects from left to right, i’m using three rocks and i want it them to spin and move from left to right, i hope you can understand, i can’t explain more b/c my English is so bad, Thank you in advance.