본문 바로가기
Unity3D/Unity & C#

Unity & C# ~ 코루틴으로 회전하기 (Rotate Coroutine)

by 캬캬백곰 2022. 5. 31.
728x90
Coroutine rotCoroutine = null;
float rotSpeed = 30.0f;

public void RotStartFunc()
{
    rotCoroutine = StartCoroutine(CoroutineRotFunc());
}

IEnumerator CoroutineRotFunc()
{
    var angles = transform.rotation.eulerAngles;
    angles.z -= Time.deltaTime * rotSpeed;
    transform.rotation = Quaternion.Euler(angles);

    yield return null;

    rotCoroutine = StartCoroutine(CoroutineRotFunc());
}

public void RotStopFunc()
{
    if (rotCoroutine != null)
        StopCoroutine(rotCoroutine);
}
728x90
반응형