Rotating a certain axis offsets the other ones?

Hello. Everytime I try to rotate my object using my code, it offsets the x rotation to 0 again. I think it has something to do with me defining my rotation when I instantiate the object, but I’m not sure. Here is my code:

                    if (!ghostOn)
					{
						ghost = (GameObject)Instantiate(Building[SelectedBuilding], 
						new Vector3(hit_.point.x - hit*.point.x/2,*_

_ hit*.point.y + (Building[SelectedBuilding].transform.localScale.y / 2),
hit.point.z - hit.point.z/2),
Quaternion.Euler (-90, 0, 0));*_

* ghostOn = true;*
* }*

* if (ghostOn && Input.GetKeyDown (KeyCode.R)) {*
* ghost.transform.rotation = Quaternion.Euler(ghost.transform.rotation.x, ghost.transform.rotation.y + 90, ghost.transform.rotation.z);*
* }*

You have a serious problem here, and a potential problem here. The serious issue is your use of ghost.transform.rotation. ‘transform.rotation’ is a Quaternion, a non-intuitive 4D structure in which the individual x, y, z, and w components have values between -1 and 1. Since you are looking for angles, you may be able to use transform.eulerAngles, but I highly recommend treating eulerAngles as write-only. Plan you code so you never have to read from them.

So to fix your code, I would replace line 13 with:

  ghost.transform.Rotate(0,90,0);

…or

  ghost.transform.Rotate(0,90,0,Space.World);

…depending on what you are looking for.