Assignment for RMIT Mixed Reality in 2020
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.

68 lines
1.8 KiB

  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class MoveBlock : MonoBehaviour
  5. {
  6. public float moveYAmount = 20.0f;
  7. public float moveSpeed = 1.0f;
  8. public float waitTime = 5.0f;
  9. public float rotateSpeed = 10.0f;
  10. private float startY;
  11. private bool goingUp = true;
  12. private float stoppedUntilTime;
  13. private float moveUpAmount;
  14. protected virtual void Start ()
  15. {
  16. startY = transform.position.y;
  17. moveUpAmount = Mathf.Abs(moveYAmount);
  18. if(moveYAmount < 0.0f)
  19. {
  20. startY -= moveYAmount;
  21. goingUp = false;
  22. }
  23. stoppedUntilTime = Time.time + waitTime;
  24. }
  25. protected virtual void Update ()
  26. {
  27. if( Time.time > stoppedUntilTime)
  28. {
  29. if(goingUp)
  30. {
  31. if(transform.position.y < startY+moveUpAmount)
  32. {
  33. Vector3 newPosition = transform.position;
  34. newPosition.y += Time.deltaTime * moveSpeed;
  35. transform.position = newPosition;
  36. }
  37. else
  38. {
  39. goingUp = false;
  40. stoppedUntilTime = Time.time + waitTime;
  41. }
  42. }
  43. else
  44. {
  45. if(transform.position.y > startY)
  46. {
  47. Vector3 newPosition = transform.position;
  48. newPosition.y -= Time.deltaTime * moveSpeed;
  49. transform.position = newPosition;
  50. }
  51. else
  52. {
  53. goingUp = true;
  54. stoppedUntilTime = Time.time + waitTime;
  55. }
  56. }
  57. }
  58. transform.Rotate(new Vector3(0.0f, rotateSpeed * Time.deltaTime, 0.0f));
  59. }
  60. }