← Todas las publicaciones
post28 de abril de 2026
Corrutinas para Secuencias Temporizadas
#csharp#unity#coroutines#animation

csharp
using System.Collections;
using UnityEngine;
public class DoorController : MonoBehaviour
{
public void Open() => StartCoroutine(OpenSequence());
private IEnumerator OpenSequence()
{
PlayCreakSound();
yield return new WaitForSeconds(0.3f);
float t = 0;
Quaternion closed = transform.rotation;
Quaternion open = closed * Quaternion.Euler(0, 90, 0);
while (t < 1f)
{
t += Time.deltaTime * 2f;
transform.rotation = Quaternion.Slerp(closed, open, t);
yield return null; // wait one frame
}
}
}