How do I rotate around z-axis as if I am rotating around x-axis?

Let’s say I have a cuboid here. When I rotate it around x-axis for 90 degrees, it stands up.

I want that when I input 90 degrees in the z-axis field, it will make the cuboid stand up too, instead of lying down like this.

I’ve tried to create an empty GameObject and make it the parent of the cuboid, then rotate the GameObject’s x-axis and y-axis by 90 degrees. This made the cuboid stands up when I am rotating the cuboid’s z-axis by 90 degrees, but it doesn’t work for other degrees like 45 degrees. I want the cuboid to rotate around z-axis as if I am rotating around x-axis for all angles. Thanks in advance.

One solution I came up with is to

  1. Get the rotation angle of the cuboid
  2. Rotate the empty parent’s x-axis by this angle
  3. Rotate the empty parent’s z-axis by -1 * this angle
    Would this work? Is so, how do I implement this? Is there any better way than this?

This is the code I used:

    var rotationCuboid = GameObject.Find("Cuboid").transform.localRotation.eulerAngles;
    var rotationEmpty = GameObject.Find("Empty").transform.localRotation.eulerAngles;
    GameObject.Find("Empty").transform.localRotation = Quaternion.Euler(rotationCuboid.z, 0, -rotationCuboid.z);

And it worked for me :D!