BrokenLaserScript.cs 2.1 KB

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