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

Answer by nur farazi

$
0
0
you can use drag code , and put a scale function , here is the code how you can use the drag function in your script , now just put a scaling funtion like (http://docs.unity3d.com/ScriptReference/Vector3.Scale.html) using UnityEngine; using System.Collections; public class Drag2 : MonoBehaviour { private float dist; private bool dragging = false; private Vector3 offset; private Transform toDrag; void Update() { Vector3 v3; if (Input.touchCount != 1) { dragging = false; return; } Touch touch = Input.touches[0]; Vector3 pos = touch.position; if(touch.phase == TouchPhase.Began) { RaycastHit hit; Ray ray = Camera.main.ScreenPointToRay(pos); if(Physics.Raycast(ray, out hit) && (hit.collider.tag == "Draggable")) { Debug.Log ("Here"); toDrag = hit.transform; dist = hit.transform.position.z - Camera.main.transform.position.z; v3 = new Vector3(pos.x, pos.y, dist); v3 = Camera.main.ScreenToWorldPoint(v3); offset = toDrag.position - v3; dragging = true; } } if (dragging && touch.phase == TouchPhase.Moved) { v3 = new Vector3(Input.mousePosition.x, Input.mousePosition.y, dist); v3 = Camera.main.ScreenToWorldPoint(v3); toDrag.position = v3 + offset; } if (dragging && (touch.phase == TouchPhase.Ended || touch.phase == TouchPhase.Canceled)) { dragging = false; } } }

Viewing all articles
Browse latest Browse all 4

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>