Rotating on a plane

I have a plane that I want to adjust my gameobject to while keeping the ability to rotate around the (new) local Y-axis. Therefore I calculated the planes normal (curUp) and planned on rotating the transform.up towards it.

Quaternion rot = Quaternion.FromToRotation(transform.up, curUp);
transform.Rotate(rot.eulerAngles.x, 0, rot.eulerAngles.z, Space.World);

That does not work as intended obviously, since I’m setting the global y axis to 0. However every attempt to transform the rotation into local space and setting the local y rotation to 0 results in a mess. What’s the correct way of doing this in Unity?

Assuming you have a specific angle you are modifying to rotate your game object, try doing it this way:

transform.up = curUp;
transform.rotation = Quaternion.AngleAxis(angle, transform.up) * transform.rotation;

Simple code to make, transform and rotate a plane

            GameObject thisPlane = GameObject.CreatePrimitive(PrimitiveType.Plane); //create plane
            thisPlane.transform.position = new Vector3(1, 1, 1); //set position
            thisPlane.transform.Rotate(-90, 0, 0); //set rotation