Rotation with time control

hi, i’d like to make a rotation with time control, that after every 1 second the object rotates (+30°) like a clock. I tried yield waitforseconds() but it doesn’t work and i don’t know if it is the right method to do this.

Thanks

private var smooth = 10.0;
private var rotat : int;

function Update ()
{
	rotat = 30;
	var target = Quaternion.Euler (0, 0, rotat);
	transform.rotation = Quaternion.Slerp(transform.rotation, target, Time.deltaTime * smooth);
}

You can do this with coroutine…

function SecondsRotation(){
     while(true){
          transform.rotate(0,0,30);
          yield WaitForSeconds(1);
     }
}

//Call method or start coroutine from any method(i.e. Start) at once like this

StartCoroutine(SecondsRotation());

You need to know how much time has passed. Now depending on your requirements, this may be as simple as just using realtimeSinceStartup. Of course you can also have a startTime and an endTime and only animate if the time is between those times.
Also if you want your game reacting to timeScale, you better add up Time.deltaTime instead of using realtimeSinceStartup.

And then you just calculate the rotation based on that time.

private var degreesPerSecond = 30.0f;
 
function Update ()
{
    var t = Time.realtimeSinceStartup;
    transform.rotation = Quaternion.Euler(0,0,t*degreesPerSecond);
}