TwinTurbine/Assets/Wind_Turbine/Scripts/TurbineController.cs
2024-05-25 13:45:40 +02:00

32 lines
949 B
C#

using UnityEngine;
using System.Collections;
public class TurbineController : MonoBehaviour
{
public float startRotationY = 0f;
public float endRotationY = 90f;
private void Start()
{
// Start the rotation when the game starts
StartCoroutine(RotateObject(startRotationY, endRotationY, 1f));
}
IEnumerator RotateObject(float startAngle, float endAngle, float duration)
{
float timeElapsed = 0f;
Quaternion startRotation = Quaternion.Euler(0, startAngle, 0);
Quaternion endRotation = Quaternion.Euler(0, endAngle, 0);
while (timeElapsed < duration)
{
transform.rotation = Quaternion.Lerp(startRotation, endRotation, timeElapsed / duration);
timeElapsed += Time.deltaTime;
yield return null;
}
// Ensure the rotation exactly matches the end rotation at the end
transform.rotation = endRotation;
}
}