-->
julis

Unity3D : Click Spawn Object and Move to point


This is the script to how to do it :

#pragma strict

var point : Transform;
var obj : Transform;
var destpoint : Transform;

function Start () {

}

function Update () {

}

function OnMouseDown () {
var x = Instantiate (obj, point.position, Quaternion.identity);
yield MoveObject(x, point.position, destpoint.position, 3.0);
 
}


function MoveObject (thisTransform : Transform, startPos : Vector3, endPos : Vector3, time : float) {
    var i = 0.0;
    var rate = 1.0/time;
    while (i < 1.0) {
        i += Time.deltaTime * rate;
        thisTransform.position = Vector3.Lerp(startPos, endPos, i);
        yield
    }
}
julis
julis
Load comments