BrokenLaserScript.cs 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. using System.Collections;
  2. using UnityEngine;
  3. namespace Subworlds.Scripts
  4. {
  5. class BrokenLaserScript : MonoBehaviour
  6. {
  7. private Renderer r;
  8. private GameObject hazard;
  9. public int anim;
  10. public int activeCount;
  11. public bool active;
  12. private bool animating;
  13. private bool running;
  14. private void Awake()
  15. {
  16. this.r = base.GetComponent<Renderer>();
  17. this.hazard = base.transform.GetChild(0).gameObject;
  18. OnEnable();
  19. }
  20. private void OnEnable()
  21. {
  22. if (!animating)
  23. base.StartCoroutine(this.Anim());
  24. if (Network.isServer)
  25. {
  26. if (!running && this.gameObject.activeSelf)
  27. base.StartCoroutine(this.Run());
  28. }
  29. }
  30. private void OnDisable()
  31. {
  32. this.r.material.mainTextureOffset = new Vector2(0f, 0f);
  33. this.animating = false;
  34. this.running = false;
  35. }
  36. [RPC]
  37. private void ChageState(bool state)
  38. {
  39. active = state;
  40. StartCoroutine(SetActiveDelay(state));
  41. }
  42. private IEnumerator SetActiveDelay(bool state)
  43. {
  44. yield return new WaitForSeconds(0.15f);
  45. hazard.SetActive(state);
  46. }
  47. private IEnumerator Run()
  48. {
  49. running = true;
  50. while (true)
  51. {
  52. yield return new WaitForSeconds(1f);
  53. base.GetComponent<NetworkView>().RPC("ChageState", RPCMode.All, new object[] { true });
  54. yield return new WaitForSeconds(2f);
  55. base.GetComponent<NetworkView>().RPC("ChageState", RPCMode.All, new object[] { false });
  56. }
  57. }
  58. // Token: 0x0600009B RID: 155 RVA: 0x0000E4C8 File Offset: 0x0000C8C8
  59. private IEnumerator Anim()
  60. {
  61. this.animating = true;
  62. while (true)
  63. {
  64. anim = (anim + 1) % 4;
  65. if (active)
  66. {
  67. this.r.material.mainTextureScale = new Vector2(0.2f, 1f);
  68. this.r.material.mainTextureOffset = new Vector2(0.2f * (anim + 1), 0f);
  69. }
  70. else
  71. {
  72. this.r.material.mainTextureScale = new Vector2(0.2f, 1f);
  73. this.r.material.mainTextureOffset = new Vector2(0f, 0f);
  74. }
  75. yield return new WaitForSeconds(0.1f);
  76. }
  77. }
  78. }
  79. }