I have a floating island made of 3D cubes (Minecraft style) and at the start of the level I let all cubes “fly” into their position to assemble into the floating island. The island is prefab which consists of many of those cubes and each cube has attached a simple script. All works fine for cubes but does not work for the trees and other objects which are made of many Poly surfaces. In fact if I have only one object made of poly surfaces the script works. As soon as I add the second object the script stops working. No error is shown. Simply nothing happens. How do I Lerp GameObject properly?
private Transform objectTransform;
private float moveDistance = 10f;
private Vector3 startPos;
private Vector3 endPos;
void Awake ()
{
objectTransform = gameObject.transform as Transform;
endPos = objectTransform.position;
startPos = endPos - Vector3.down * moveDistance * endPos.y;
}
void Update ()
{
//increment timer once per frame
currentLerpTime += Time.deltaTime;
if (currentLerpTime > lerpTime) {
currentLerpTime = lerpTime;
}
//lerp!
float perc = currentLerpTime / lerpTime;
objectTransform.position = Vector3.Lerp (startPos, endPos, perc);
}