Quantcast
Channel: Answers for "How to change the scaling of a gameobject during runtime?"
Viewing all articles
Browse latest Browse all 4

Answer by robertbu

$
0
0
If the camera is axes aligned, then dragging out a Quad is relatively easy. Create a new scene. Create a Quad (GameObject>Create Other>Quad). Attach the following script: #pragma strict private var pos1 : Vector3; private var pos2 : Vector3; function Update () { if (Input.GetMouseButtonDown(0)) { pos1 = Input.mousePosition; pos1.z = transform.position.z - Camera.main.transform.position.z; pos1 = Camera.main.ScreenToWorldPoint(pos1); transform.localScale.x = 0; } if (Input.GetMouseButton(0)) { pos2 = Input.mousePosition; pos2.z = transform.position.z - Camera.main.transform.position.z; pos2 = Camera.main.ScreenToWorldPoint(pos2); var v3 = pos2 - pos1; transform.localScale.x = v3.magnitude; transform.position = pos1 + v3 * 0.5; transform.rotation = Quaternion.FromToRotation(Vector3.right, v3); } }

Viewing all articles
Browse latest Browse all 4

Trending Articles