// Update is called once per frame void Update() { if (terrainGenerator.ChunkExists(transform.position)) { if (!animating && !terrainGenerator.InTerrain(transform.position, 0f)) { animating = true; GetComponent <Collider>().enabled = false; initialDist = (transform.position - target.transform.position).magnitude; } if (animating) { float dist = (transform.position - target.transform.position).magnitude; float scale = dist / initialDist; transform.localScale = new Vector3(scale, scale, scale); transform.position = Vector3.MoveTowards(transform.position, target.transform.position - Vector3.up, animationSpeed * Time.deltaTime); if (dist < 1.5f) { Destroy(gameObject); } } } }