Browse Source

[2.0.3.9] Laser hazard.

Zariteis 4 years ago
parent
commit
6b3c7903b5
2 changed files with 89 additions and 0 deletions
  1. BIN
      Assets/brokenLaser.png
  2. 89 0
      Scripts/BrokenLaserScript.cs

BIN
Assets/brokenLaser.png


+ 89 - 0
Scripts/BrokenLaserScript.cs

@@ -0,0 +1,89 @@
+using System.Collections;
+using UnityEngine;
+
+namespace Ships.Scripts
+{
+  class BrokenLaserScript : MonoBehaviour
+  {
+    private Renderer r;
+    private GameObject hazard;
+    public int anim;
+    public int activeCount;
+
+    public bool active;
+
+    private bool animating;
+    private bool running;
+
+    private void Awake()
+    {
+      this.r = base.GetComponent<Renderer>();
+      this.hazard = base.transform.GetChild(0).gameObject;
+      OnEnable();
+    }
+
+    private void OnEnable()
+    {
+      if (!animating)
+        base.StartCoroutine(this.Anim());
+      if (Network.isServer)
+      {
+        if (!running && this.gameObject.activeSelf)
+          base.StartCoroutine(this.Run());
+      }
+    }
+
+    private void OnDisable()
+    {
+      this.r.material.mainTextureOffset = new Vector2(0f, 0f);
+      this.animating = false;
+      this.running = false;
+    }
+
+    [RPC]
+    private void ChageState(bool state)
+    {
+      active = state;
+      StartCoroutine(SetActiveDelay(state));
+    }
+
+    private IEnumerator SetActiveDelay(bool state)
+    {
+      yield return new WaitForSeconds(0.15f);
+      hazard.SetActive(state);
+    }
+
+    private IEnumerator Run()
+    {
+      running = true;
+      while (true)
+      {
+        yield return new WaitForSeconds(1f);
+        base.GetComponent<NetworkView>().RPC("ChageState", RPCMode.All, new object[] { true });
+        yield return new WaitForSeconds(2f);
+        base.GetComponent<NetworkView>().RPC("ChageState", RPCMode.All, new object[] { false });
+      }
+    }
+
+    // Token: 0x0600009B RID: 155 RVA: 0x0000E4C8 File Offset: 0x0000C8C8
+    private IEnumerator Anim()
+    {
+      this.animating = true;
+      while (true)
+      {
+        anim = (anim + 1) % 4;
+        if (active)
+        {
+          this.r.material.mainTextureScale = new Vector2(0.2f, 1f);
+          this.r.material.mainTextureOffset = new Vector2(0.2f * (anim + 1), 0f);
+        }
+        else
+        {
+          this.r.material.mainTextureScale = new Vector2(0.2f, 1f);
+          this.r.material.mainTextureOffset = new Vector2(0f, 0f);
+        }
+        yield return new WaitForSeconds(0.1f);
+      }
+    }
+  }
+}