OnCollisionEnter Question

I’m bulding a top down scroller, once the player collide with certain object the camera flip 180 degrees around the Z axis, now, i want the fliped screen only for limted time lets say 3 seconds, and after that the screen will flip in another 180 degress around the Z axis to bring the player back to the noraml view, something is wrong with my implemntation, help me please

    void OnTriggerEnter(Collider col)
    {
        Destroy(gameObject); 

        if (col.gameObject.tag == "Player")
        {
            GameObject.FindGameObjectWithTag("MainCamera").transform.Rotate(new Vector3(0f, 0f, 180f));
            do
            {
                flipScreenTimer += Time.deltaTime;
            } while (flipScreenTimer < 3.0f);

            GameObject.FindGameObjectWithTag("MainCamera").transform.Rotate(new Vector3(0f, 0f, 180f));
            flipScreenTimer = 0f;
        }

I am not a fan of ‘while’ loops like that, preferring to use Update, but if you must, you must put a ‘yield’ in that loop so the system can update Time.deltaTime.

You should never use loops like this. I myself almost never use loops at all in Unity; they just don’t have much use.

You should look into Coroutines, they would help you out a lot not only in this situation but many others that you’re bound to run into.

Also, if you don’t understand what the issue with your code is you should really study programming first before you get into game development. It helps if you have an understanding of what is going on under the hood.