How do i rotate to a specific axis?

So, i want to rotate my object to X20 Y0 Z0 on the rotational axis when a player holds down a key, and when he lets go, i want to zero it all out. How can i do that? I would really need help with this :c

anyone? no?

Something like this?

if (Input.GetKey("a")) {
transform.rotation = Quaternion.Euler(20f, 0f, 0f);
}
else {
transform.rotation = Quaternion.identity; //same as 0, 0, 0
}

thanks! it works! one more thing, how to i make the other zeroes not care? so for example when the thing is parented under a other thing that spins, it doesn’t spin with it… any fix for that?

I don’t quite follow, but I’m gonna guess what you mean: when the parent spins, you want the thing this script is for to spin with it, and right now, it just sets the rotation based on global space. Is that about right? If so, you want to set transform.localRotation instead.