Help to rotate stop rotate

hi everyone. Im trying to figuere out how to make something rotate on himself, and stop at 90º then wait for some seconds and start to rotate over again.
Im new in C# I used to write on Js.

I was thinkings in something simple like:

transform.Rotate (new Vector3 (0, 0, 1)*speed, Space.Self);

with something like this, I can make the object to rotate. But I dont know how to stop it in the 90º or even how to make it wat some seconds before start to rotating again since “yield” work pretty different in C#

Im kinda lost right now :c I would really appreciate some help

I think yo could do everything you need to in the update method. This should be a starting point.

float startTime;
float endTime;
float startAngle = 0.0f;
float endAngle = 90.0f;

void Start() {
  startTime = Time.time + 5.0f;
  endTime = Time.time + 10.0f;
}

void Update() {
  // Set the angle
  if (Time.time > startTime) {
    float t = (Time.time - startTime) / (endTime - startTime)
    float rotate = Mathf.LerpAngle(startAngle, endAngle, t);
    transform.localEulerAngles = new Vector3(0.0f, rotate, 0.0f);
  }

  // Finish and get ready for next rotation
  if (Time.time > endTime) {
    startTime = Time.time + 5.0f;
    endTime = Time.time + 10.0f;
  }
}
1 Like

Tha

Thanks, just now I was writting somthing similar, but what you give me help me to improve it. When finish and working I’ll post here so you can let’me what you think.

Thank you!

Finnally I got it working:

using UnityEngine;
using System.Collections;

public class BigGear : MonoBehaviour
{
    public float startTime;
    public float endTime;
   
    void Start()
        {
        startTime = Time.time + 0.0f;
        endTime = Time.time + 3.0f;
        }
   
    void Update()
        {
        if (Time.time > startTime)
            {
            transform.Rotate (new Vector3 (0, 0, 1)*4, Space.Self);
            }
        // Finish and get ready for next rotation
        if (Time.time > endTime)
            {
            startTime = Time.time + 1.0f;
            endTime = Time.time + 4.0f;
            transform.localEulerAngles = new Vector3(0.0f, 0.0f, 12);
            }
        }
}

Thanks a lot srsly! :smile: