using System.Collections; using UnityEngine; namespace MonsterNests.Scripts { class GoldenShroomScript : EnemyScript { private bool attacking; private Vector3 dir; private bool moving; private float spd; private bool shooting; private void Awake() { r = gameObject.GetComponent(); t = transform; b = transform.GetChild(0).GetChild(0).gameObject; e = transform.GetChild(0).gameObject; networkR2 = gameObject.GetComponent(); trig[0] = gameObject.transform.GetChild(1).gameObject; trig[1] = gameObject.transform.GetChild(2).gameObject; var drops = new int[] { 24, 53, 53 }; Initialize(750, 8, 103, drops, 50); if (Network.isServer) { base.StartCoroutine(this.Bolt()); } } [RPC] private void MakeFace() { base.GetComponent().PlayOneShot((AudioClip)Resources.Load("Au/roll"), Menuu.soundLevel / 10f); } private IEnumerator MF() { yield return new WaitForSeconds(0.8f); yield break; } private IEnumerator Bolt() { for (; ; ) { if (this.target && Vector3.Distance(this.target.transform.position, this.t.position) < 20f) { this.shooting = true; base.GetComponent().RPC("MakeFace", RPCMode.All, new object[0]); yield return new WaitForSeconds(0.2f); for (int i = 0; i < 3; i++) { GameObject p = (GameObject)Network.Instantiate(Resources.Load("proj/MonsterNests/goldenShroom"), this.t.position + new Vector3(0, i - 1, 0), Quaternion.identity, 0); p.SendMessage("EnemySet", this.target.transform.position, SendMessageOptions.DontRequireReceiver); } yield return new WaitForSeconds(0.5f); this.shooting = false; } yield return new WaitForSeconds(2f); } yield break; } private void Update() { if (Network.isServer) { if (this.target) { if (Mathf.Abs(this.target.transform.position.x - this.t.position.x) < 80f) { if (!this.attacking) { this.attacking = true; base.StartCoroutine(this.Attack()); } } else { this.target = null; this.r.velocity = new Vector3(0f, 0f, 0f); } } if (this.moving && !this.knocking && !this.shooting) { this.r.velocity = this.dir * this.spd; } } } private IEnumerator Attack() { if (this.target.transform.position.x > this.t.position.x) { this.e.transform.rotation = Quaternion.Euler(0f, 180f, 0f); } else { this.e.transform.rotation = Quaternion.Euler(0f, 0f, 0f); } if (UnityEngine.Random.Range(0, 4) == 0) { this.spd = 3f; this.dir = this.t.position - this.target.transform.position; } else { this.spd = 12f; Vector3 a = new Vector3(this.target.transform.position.x, this.target.transform.position.y + (float)UnityEngine.Random.Range(-15, 15), 0f); this.dir = a - this.t.position; } this.dir.Normalize(); this.moving = true; yield return new WaitForSeconds((float)UnityEngine.Random.Range(1, 3) * 0.2f); this.moving = false; yield return new WaitForSeconds(0.5f); this.attacking = false; yield break; } } }