How can i rotate object smooth without stop ?

I’m using this code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class SpinObject : MonoBehaviour {

    
    
    // Use this for initialization
    void Start () {

        
    }
	
	// Update is called once per frame
	void Update ()
    {
        StartCoroutine(ContinuousRotation());
    }

    IEnumerator ContinuousRotation()
    {
        while (true)
        {
            transform.Rotate(Vector3.forward, 10);
            yield return new WaitForSeconds(5f);
        }
    }
}

It’s rotating the object but the problem is no matter what time i’m setting when running the game the rotating speed is the same.
I tried: yield return new WaitForSeconds(1f); then 5f in the original it was 0.01f but the speed never change.

Second problem is that the rotating making the object some flickering not flickering but some interruption to the eyes it’s not really rotating smooth. Maybe the problem is the speed ?

Keep it simple?

void Update()
{
    transform.rotation += Vector3.forward * time.deltatime * speed;
}

Sorry for crap formatting, on my phone. Good luck

You have to start the coroutine inside the Start function, not the Update one. Otherwise, every frame, you will run a coroutine. Thus, you will have hundreds of coroutines trying to rotate your object.

Moreover, I think you don’t quite understand how coroutines work. Take this code :

void Start () {
     StartCoroutine(ContinuousRotation());
 }

 IEnumerator ContinuousRotation()
 {
     float duration = 10f ;
     float speed = 1 ;
     WaitForSeconds wait = new WaitForSeconds(5f);
     while (true)
     {
         for( float time = 0 ; time < duration ; time += Time.deltaTime )
         {                     
             transform.Rotate(Vector3.forward, speed * Time.deltaTime);
             yield return null ;
         }
         yield return wait;
     }
 }