Car popups Unity 3D

Hi
I want to make pop ups for my car so

  • when you press p on the keyboard the object will turn 60 degrees
  • when pressed again it will go back to 0

Please tell me instructions on how to do this Thank you

Hey chillis,
I will guess you are using the old input system for this.
Also, depending on how your car is supposed to work, you have to go deeper into how tires work, but for just making an object rotate, this should suffice:

using UnityEngine;

public class CarRotation : MonoBehaviour
{
    // You can reference your object in the inspector here
    [SerializeField]
    private GameObject obj; // The object in question

    // A bool so the script knows where to turn at the next input

    private bool isObjTurned = false; // If you want to turn in the other direction, just set this to true in the beginning

    // The angle you want to turn it
    private readonly float turnAngle = 60f; // Default is your 60 degrees

    void Update()
    {

        if (Input.GetKeyDown(KeyCode.P))
        {
            if (!isObjTurned)
            {
                // Rotate Object by 60 degrees
                obj.transform.Rotate(new Vector3(0, turnAngle, 0)); // Assuming you want it to turn 60 degrees horizontally

                // Update bool
                isObjTurned = true;
            }
            else
            {
                // Rotate Object by -60 degrees
                obj.transform.Rotate(new Vector3(0, - turnAngle, 0)); // Turn back to zero

                // Update bool
                isObjTurned = false;

            }
        }
    }
}