Advertisement
Guest User

Untitled

a guest
Oct 21st, 2014
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Platforms : MonoBehaviour {
  5.  
  6. public bool upDown;
  7. public bool leftRight;
  8. public float transDistance;
  9. public bool damaging;
  10. public bool disappearing;
  11. public float safeLength;
  12. public float warningLength;
  13. public float dangerLength;
  14. public float damageGiven;
  15. Vector3 startPos;
  16. Vector3 endPos;
  17. float progress = 1f;
  18. public float moveSpeed = 10f;
  19. public int stage = 0;
  20. float startTime = 0;
  21. float endtime;
  22.  
  23. // Use this for initialization
  24. void Start () {
  25.  
  26. startPos = new Vector3(gameObject.transform.position.x, gameObject.transform.position.y, gameObject.transform.position.z);
  27. endtime = safeLength;
  28.  
  29. }
  30.  
  31. // Update is called once per frame
  32. void Update () {
  33.  
  34.  
  35. if (upDown || leftRight)
  36. {
  37. lerpMove();
  38. }
  39.  
  40. if (damaging)
  41. {
  42. if (timer(safeLength) && stage == 0)
  43. {
  44. print("wark");
  45. damRun(1);
  46. }
  47. if (timer(warningLength) && stage == 1)
  48. {
  49. print("wink");
  50. damRun(2);
  51. }
  52. if (timer(dangerLength) && stage == 2)
  53. {
  54. print("wonk");
  55. damRun(3);
  56. }
  57.  
  58. }
  59.  
  60. if (disappearing)
  61. {
  62. disRun();
  63. }
  64.  
  65. }
  66.  
  67. bool timer(float countdown)
  68. {
  69. if (Time.time > endtime)
  70. {
  71. endtime = Time.time + countdown;
  72. return true;
  73. }
  74. return false;
  75.  
  76. }
  77.  
  78. void damRun(int callstage)
  79. {
  80.  
  81. if (stage == 0)
  82. {
  83. renderer.material.color = Color.white;
  84. }
  85. else if (stage == 1)
  86. {
  87. renderer.material.color = Color.yellow;
  88. }
  89. else if (stage == 2)
  90. {
  91. renderer.material.color = Color.red;
  92. }
  93. stage = callstage;
  94.  
  95. }
  96.  
  97. void disRun()
  98. {
  99.  
  100. }
  101.  
  102. void lerpMove ()
  103. {
  104. if (upDown)
  105. {
  106. endPos = new Vector3(startPos.x, (startPos.y + transDistance), startPos.z);
  107.  
  108. }
  109. else if (leftRight)
  110. {
  111. endPos = new Vector3((startPos.x + transDistance), startPos.y, startPos.z);
  112. }
  113.  
  114.  
  115. progress = (Time.time - startTime) / moveSpeed;
  116. transform.localPosition = Vector3.Lerp(startPos, endPos, progress);
  117. if (progress >= 1)
  118. {
  119. progress = 1;
  120. }
  121. }
  122. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement