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?
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));
}