Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. void Update(){
  2. for (i = 0; i <= 2; i++) {
  3. platform.SetActive (false);
  4. if (i >= 1 ) {
  5. i--;
  6. platform.SetActive (true);
  7. }
  8. }
  9. }
  10.  
  11. float blinkInterval = 1.0f; // Turn on/off every second
  12.  
  13. void Start() {
  14. StartCoroutine("Blink");
  15. }
  16.  
  17. IEnumerator Blink() {
  18. while(true) {
  19. platform.SetActive(true);
  20. yield return new WaitForSeconds(blinkInterval / 2f);
  21. platform.SetActive(false);
  22. yield return new WaitForSeconds(blinkInterval / 2f);
  23. }
  24. }
  25.  
  26. public class ActiveAlternator : MonoBehaviour {
  27.  
  28. [Tooltip("Target object to turn on/off (NOT this object or its parents!")]
  29. public GameObject target;
  30.  
  31. [Tooltip("Seconds to wait between activating / deactivating the object")]
  32. public float interval = 1f;
  33.  
  34. // IEnumerator makes this run as a coroutine we can suspend & resume with yield.
  35. IEnumerator Start() {
  36. if(target == gameObject)
  37. Debug.LogError("ActiveAlternator cannot target itself and still re-activate");
  38.  
  39.  
  40. // Infinite loop! But it's OK, because we'll tell it to take breaks.
  41. while(true) {
  42.  
  43. // This passes control back to the engine so it can draw the frame,
  44. // and asks to resume this method on the next line after some time.
  45. yield return new WaitForSeconds(interval);
  46.  
  47. // If the object was active, set it inactive, and vice versa.
  48. target.SetActive(!target.activeSelf);
  49.  
  50. // Then loop to wait, and alternate again, forever.
  51. }
  52.  
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement