Hi! I have this object in my game and I want it to rotate every 5 seconds, opening and closing the street. In order to do that, I need it to rotate in the X axis from 0 degrees (closed) to -90 degrees (open).
Currently this is the code I’m using:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GuaritaRotation : MonoBehaviour
{
public int waitTime;
float angle = 90f;
void Start()
{
StartCoroutine(Coroutine());
}
IEnumerator Coroutine()
{
while (true)
{
if (angle == 90f)
{
angle = -90f;
}
else if(angle == -90f)
{
angle = 90f;
}
transform.Rotate(angle, 0.0f, 0f);
yield return new WaitForSeconds(waitTime);
}
}
}
It works but the object goes directly from 0 to -90 and I’d like it to slowly rotate from one angle to another. I’m having some troubles discovering how to make that, so any help is appreciated!