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.

48 lines
1.3 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class CrushingBoulder : MonoBehaviour
  5. {
  6. public bool triggeranimate;
  7. public bool triggeranimate1;
  8. private void Update()
  9. {
  10. //for testing purposes
  11. if (triggeranimate == true)
  12. {
  13. Animate();
  14. triggeranimate = false;
  15. }
  16. if (triggeranimate1 == true)
  17. {
  18. returnToPosition();
  19. triggeranimate1 = false;
  20. }
  21. }
  22. IEnumerator FallRaiseCoroutine(float dropDistance)
  23. {
  24. float elapsedTime = 0;
  25. Vector3 startPosition = transform.position;
  26. Vector3 endPosition = new Vector3(transform.position.x, transform.position.y + dropDistance, transform.position.z);
  27. float time = 0.8f;
  28. while (elapsedTime < time)
  29. {
  30. transform.position = Vector3.Lerp(startPosition, endPosition, (elapsedTime / time));
  31. yield return new WaitForEndOfFrame();
  32. elapsedTime += Time.deltaTime;
  33. }
  34. transform.position = endPosition;
  35. }
  36. public void Animate()
  37. {
  38. StartCoroutine(FallRaiseCoroutine(-2.0f));
  39. }
  40. public void returnToPosition()
  41. {
  42. StartCoroutine(FallRaiseCoroutine(2.0f));
  43. }
  44. }