Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class MovingSpikeShowedNew : MonoBehaviour
  6. {
  7.  
  8. public bool showed;
  9. public bool hided;
  10.  
  11. public bool showing;
  12. public bool hiding;
  13.  
  14. private Vector3 showedPosition;
  15. private Vector3 hidedPosition;
  16.  
  17. public float moveTime; // 0.005
  18. public float waitTime; // 0.5
  19.  
  20. private float openSize;
  21.  
  22. private GameObject player;
  23.  
  24.  
  25. // Start is called before the first frame update
  26. void Start()
  27. {
  28. player = GameObject.Find("Player New");
  29. showedPosition = transform.localPosition;
  30. openSize = 0.08f;
  31.  
  32. }
  33.  
  34. // Update is called once per frame
  35. void Update()
  36. {
  37. if (transform.localPosition == showedPosition)
  38. {
  39. showed = true;
  40. hided = false;
  41. showing = false;
  42. }
  43.  
  44.  
  45. if (transform.localPosition == showedPosition - new Vector3(0, openSize, 0))
  46. {
  47. showed = false;
  48. hided = true;
  49. hiding = false;
  50. }
  51.  
  52. if (hiding)
  53. {
  54. if (player.GetComponent<PlayerNew>().levelrotating == false)
  55. {
  56. transform.Translate(Vector3.down * moveTime);
  57. showing = false;
  58. showed = false;
  59. hided = false;
  60. }
  61.  
  62. }
  63.  
  64. if (showing)
  65. {
  66. if (player.GetComponent<PlayerNew>().levelrotating == false)
  67. {
  68. transform.Translate(Vector3.up * moveTime);
  69. hiding = false;
  70. showed = false;
  71. hided = false;
  72. }
  73.  
  74. }
  75.  
  76. if (showed)
  77. {
  78. StartCoroutine(hide());
  79. }
  80.  
  81. if (hided)
  82. {
  83. StartCoroutine(show());
  84. }
  85.  
  86.  
  87.  
  88. }
  89.  
  90. IEnumerator show()
  91. {
  92. yield return new WaitForSecondsRealtime(waitTime);
  93. showing = true;
  94.  
  95. }
  96.  
  97. IEnumerator hide()
  98. {
  99. yield return new WaitForSecondsRealtime(waitTime);
  100. hiding = true;
  101.  
  102. }
  103.  
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement