- Home /
Question by
medkatimx · Oct 11, 2021 at 02:26 PM ·
rotate objectstartcoroutinerepeat
i wrote this code to rotate a cube wait for seconds and Return it to its original place What can you do in my place
void Update() { if (rotation1 == true) { rotatehead(); }
if (rotation2 == true)
{
Quaternion target2 = Quaternion.Euler(0, 0, 0);
transform.rotation = Quaternion.RotateTowards(transform.rotation, target2, speed * Time.deltaTime);
if (transform.rotation == target2)
{
rotation2 = false;
}
}
}
void rotatehead()
{
Quaternion target = Quaternion.Euler(0, 180, 0);
transform.rotation = Quaternion.RotateTowards(transform.rotation, target, speed * Time.deltaTime);
if (transform.rotation == target)
{
rotation1 = false;
StartCoroutine(returnHead());
}
}
private IEnumerator returnHead()
{
yield return new WaitForSeconds(5f);
rotation2 = true;
yield return new WaitForSeconds(5f);
rotation1 = true;
}
Comment
Your answer
Follow this Question
Related Questions
How to move child objects perpendicular to parent object's rotation? 2 Answers
The power of the Force 0 Answers
Question about specific way of rotation 0 Answers
Can't rotate GameObject with Animation in Unity 5.3? 1 Answer
Button as child object 0 Answers