I have encountered a very unusual issue and hope somebody can explain it to me and help me find a solution. Basically, here is what I’m trying to accomplish: I want to instantiate a game object, set it’s parent, tweak it’s position, and make sure there is no rotation.
My code:
Transform player = GameObject.FindGameObjectWithTag(Tags.player).transform;
//instantiate the object
GameObject itemInHand = (GameObject)Instantiate(ItemDictionary.blah blah balh);
//set the parent
itemInHand.transform.SetParent(player);
//tweak it's position
itemInHand.transform.localPosition = new Vector3(-0.681f, -0.547f, 1.57f);
//make sure there is no rotation
itemInHand.transform.rotation = Quaternion.identity;
Everything works great except for the rotation. When I step through the code, it works and is set to zero, but as soon as I step out of the code and the game resumes, the rotation is set to a random value. Anyone know why that would happen?