- Home /
Question by
driferia · May 01, 2013 at 12:36 AM ·
transformrotatelocalscale
transform.localScale unexpected behavior after Rotate()
I have a game object (which is has a scaled transform parent) that I am scaling and rotating in the following way:
OriginalScale = this.transform.localScale;
this.transform.localScale = OriginalScale;
this.transform.Rotate (0, 0, 90);
The game object becomes very distorted after the rotation is executed. However, the following does not cause distortion:
//OriginalScale = this.transform.localScale;
//this.transform.localScale = OriginalScale;
this.transform.Rotate (0, 0, 90);
Can someone explain why?
Comment
Answer by prototype7 · May 01, 2013 at 02:58 AM
If you put that code inside Update than it will scaled every frame continuously and looks like distorted, because Update is called every frame, if the MonoBehaviour is enabled.
Sample Used inside Update with drag snippet
private Vector3 originalScale;
private float distance;
// Use this for initialization
void Start () {
distance = Vector3.Distance(transform.position, Camera.main.transform.position);
}
// Update is called once per frame
void Update () {
if (Input.GetMouseButtonDown(0))
{
originalScale = this.transform.localScale;
this.transform.localScale = originalScale;
this.transform.Rotate(0, 0, 90);
}
// Drag Script
if (Input.GetMouseButton(0))
this.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, distance));
}
The code is not inside update and does not get called every frame.
okay since i didn't know your whole script, i am just guessing if you have parent in the transform, you should use
transform.localRotation = Quaternion.Euler(0, 0, 90);