Quantcast
Channel: Latest Questions by GabeGabe
Viewing all articles
Browse latest Browse all 26

How to use a coroutine inside the Update in Unity to wait for seconds to rotate the camera? (C#)

$
0
0
This is part of my code: void Update(){ CameraFlip(); } void CameraFlip(){ Quaternion target = Quaternion.Euler (0, 0, 180); cameraTransform.rotation = Quaternion.Slerp (cameraTransform.rotation, target, Time.deltaTime * 4.0f); Debug.Log (cameraTransform.rotation.ToString ()); StartCoroutine("CameraFlipCoroutine"); } public IEnumerator CameraFlipCoroutine(){ yield return new WaitForSeconds (Random.Range(6f,12f)); if (gameIsPlaying == false) yield return null; Quaternion target = Quaternion.Euler (0, 0, 0); cameraTransform.rotation = Quaternion.Slerp (cameraTransform.rotation, target, Time.deltaTime * 4.0f); Debug.Log (cameraTransform.rotation.ToString ()); } So What I would like to do is to rotate the camera with 180 angles if something is happened in the update method. (For example, the player hit an enemy) And after a few seconds the camera turns back to its original position. With my code the first part is OK, it turns as I wanted but then when the coroutine part comes, it starts turning but it's lagging and it is not smooth. I don't know. Is there any other way to do this?

Viewing all articles
Browse latest Browse all 26

Latest Images

Trending Articles





Latest Images