Advertisement
Zuvi

Untitled

Jun 3rd, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.23 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class PlatformMovement : MonoBehaviour
  6. {
  7. public bool isVertical = true;
  8. public float start;
  9. public float end;
  10. public float speed = 4;
  11.  
  12. public float waitingLenght = .5f;
  13. private float waitingTime = 0f;
  14. private bool isWaiting = false;
  15. private bool movingToEnd=true;
  16.  
  17.  
  18. // Update is called once per frame
  19. void Start()
  20. {
  21.  
  22. }
  23. void Update()
  24. {
  25. if (isVertical)
  26. {
  27. if (movingToEnd && !isWaiting)
  28. {
  29. transform.Translate(Vector2.right * speed * Time.deltaTime);
  30. }
  31. if (!movingToEnd && !isWaiting)
  32. {
  33. transform.Translate(Vector2.left * speed * Time.deltaTime);
  34. }
  35. if (transform.position.x >= end && movingToEnd == true)
  36. {
  37. movingToEnd = false;
  38. isWaiting = true;
  39. waitingTime = waitingLenght;
  40. }
  41. if (transform.position.x <= start && movingToEnd == false)
  42. {
  43. movingToEnd = true;
  44. isWaiting = true;
  45. waitingTime = waitingLenght;
  46. }
  47. }
  48. else
  49. {
  50. if (movingToEnd && !isWaiting)
  51. {
  52. transform.Translate(Vector2.up * speed * Time.deltaTime);
  53. }
  54. if (!movingToEnd && !isWaiting)
  55. {
  56. transform.Translate(Vector2.down * speed * Time.deltaTime);
  57. }
  58. if (transform.position.y >= end && movingToEnd == true)
  59. {
  60. movingToEnd = false;
  61. isWaiting = true;
  62. waitingTime = waitingLenght;
  63. }
  64. if (transform.position.y <= start && movingToEnd == false)
  65. {
  66. movingToEnd = true;
  67. isWaiting = true;
  68. waitingTime = waitingLenght;
  69. }
  70. }
  71. if (isWaiting)
  72. {
  73. waitingTime -= Time.deltaTime;
  74. if (waitingTime <= 0)
  75. isWaiting = false;
  76. }
  77. }
  78. void Wait(float seconds)
  79. {
  80.  
  81. }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement