how to perform commands in order by script?

When we write

void Update() 
Debug.Log("this is 1");
Debug.Log("this is 2");

the results come as

this is 1

this is 2

but lets say when we try to rotate an object, then rotate again like in this script below

  void Update()
			transform.rotation = Quaternion.Lerp (rot1, rot2, Time.deltaTime * 0.9f);
			transform.rotation = Quaternion.Lerp (rot2, rot1, Time.deltaTime * 0.9f);

then we only get the second one ongoing…

how to make it complete the first command firstly then the second command?

I tried using the ** yield return new WaitForSeconds(1)** with coroutine, but no luck!

can anyone enlighten me in this matter?

The reason that it’s only doing the second line of code is because the second one just replaces the first one entirely. Say you have an int. You set it to 1, and then set it to 2 in the line after. The final result of the int will always be 2.

Programming will always fire commands in the correct order. Depending on what you’re trying to accomplish, you just need to give it the correct commands :stuck_out_tongue: If you want to do one rotation, and then another one based on the first one, you can add Quaternions together to create compound rotations.

To add two Quaternions, you need to multiply the first rotation by the second rotation. So you can write:

transform.rotation = Quaternion.Lerp(rot1, rot2, Time.deltaTime * 0.9f) * Quaternion.Lerp(rot2, rot1, Time.deltaTime*0.9f);