/// <summary> /// Smooth interpolation of scale and camera position /// </summary> /// <param name="scale"></param> /// <returns></returns> IEnumerator changeScale(Vector3 scale) { var selectedGearAtStart = gearScript.selectedGear; //Camera var y = (scale.x > scale.z) ? scale.x : scale.z; var speed = Mathf.Abs(Vector3.Magnitude(scale - transform.localScale)); while (true) { var wantedPosition = new Vector3(0, Mathf.Clamp(y, 2, 100), 0); var position = Camera.main.transform.position; Camera.main.transform.position = Vector3.MoveTowards(position, wantedPosition, Time.deltaTime * dimensionChangeSpeed * speed); //Scale transform.localScale = Vector3.MoveTowards(transform.localScale, scale, Time.deltaTime * dimensionChangeSpeed * speed); if (transform.localScale == scale) { break; } yield return(new WaitForEndOfFrame()); } isChanging = false; gearScript.SelectGear(selectedGearAtStart); gearScript.showGearToPlace = false; coordScript.text = storedCoordinates; coordScript.PlaceGearsFromCoordinates(storedCoordinates); trashBin.Setup(); }
IEnumerator AnimateGears(List <Gear> gearList) { coordScript.UpdateDecimals(); for (int i = 0; i < gearList.Count; i++) { if (gearList[i].gameObject == null) { goto Foo; } gearList[i].position = new Vector3(gearList[i].position.x, Camera.main.transform.position.y + i * 2 + 5, gearList[i].position.z); } while (true) { for (int i = 0; i < gearList.Count; i++) { if (gearList[i].gameObject == null) { goto Foo; } var wantedPosition = new Vector3(gearList[i].position.x, gearScript.placeGearHeight, gearList[i].position.z); //((camY + 3) * (camY + 3) - gearY * gearY) / 20 //((gearY < camY + 2) ? 10 : 25)) gearList[i].position = Vector3.MoveTowards(gearList[i].position, wantedPosition, Time.deltaTime * gearDropSpeed * 10); } bool isDone = true; foreach (var gear in gearList) { if (gear.position.y != gearScript.placeGearHeight) { isDone = false; } } if (isDone) { break; } yield return(new WaitForEndOfFrame()); } Foo: gearScript.SelectGear(selectedGearBeforeGenerate); gearScript.canPlaceGear = false; gearScript.showGearToPlace = false; yield return(null); }