You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
905 B

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CubeWithCrystals : MonoBehaviour
  5. {
  6. bool characterInWater = false;
  7. public GameObject crystals;
  8. IEnumerator GrowShrinkCoroutine(Vector3 endPosition)
  9. {
  10. float elapsedTime = 0;
  11. Vector3 startPosition = crystals.transform.position;
  12. float time = 0.8f;
  13. while (elapsedTime < time)
  14. {
  15. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  16. yield return new WaitForEndOfFrame();
  17. elapsedTime += Time.deltaTime;
  18. }
  19. crystals.transform.position = endPosition;
  20. }
  21. public void Animate()
  22. {
  23. StartCoroutine(GrowShrinkCoroutine(new Vector3(0, 1, 0)));
  24. }
  25. public void returnToPosition()
  26. {
  27. StartCoroutine(GrowShrinkCoroutine(new Vector3(0, 0, 0)));
  28. }
  29. }