IEnumerator Spawn() { while (true) { for (float timer = secondsBetweenSkulls; timer >= 0; timer -= Time.deltaTime) { while (gateManager.pause) { yield return(null); } yield return(null); } if (nextSkull != -1 && Active && !gateManager.pause) { float angularVelocity = UnityEngine.Random.Range(angularVelocityRange[0], angularVelocityRange[1]); int rotationDirection = UnityEngine.Random.Range(0, 2); if (rotationDirection == 0) { rotationDirection = -1; } angularVelocity *= rotationDirection; GameObject skullInstance = Instantiate(skullPrefab, this.transform.position, Quaternion.AngleAxis(UnityEngine.Random.Range(0, 91), new Vector3(0, 0, 1))); skullInstance.transform.SetParent(this.transform); skullInstance.GetComponent <SpriteRenderer>().sprite = gateManager.skullSprites[nextSkull]; skullInstance.GetComponent <Rigidbody2D>().angularVelocity = angularVelocity; skullInstance.GetComponent <Skull>().skullNr = nextSkull; skullInstance.GetComponent <Skull>().gate = this; SkullType skullType = new SkullType(); if (nextSkull >= 0 && nextSkull < 6) { skullType = SkullType._1X6; } else if (nextSkull >= 6 && nextSkull < 10) { skullType = SkullType._7X10; } else if (nextSkull >= 10 && nextSkull < 16) { skullType = SkullType._11X16; } else if (nextSkull >= 16 && nextSkull < 18) { skullType = SkullType._17X19; } skullInstance.GetComponent <Skull>().skullType = skullType; if (!gateManager.IsWanted(nextSkull)) { if (UnityEngine.Random.Range(0.0f, 1.0f) <= powerUpChance) { skullInstance.GetComponent <Skull>().PowerUp(); } } skulls.Add(skullInstance.GetComponent <Skull>()); nextSkull = gateManager.RandomSkull(true); } } }
public void PowerUp() { IsPowerUp = true; PowerType = (PowerUpType)Random.Range(0, 3); switch (PowerType) { case PowerUpType.SPEED: this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("BUFF_3"); skullType = SkullType.RED; break; case PowerUpType.SLOW: this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("BUFF_2"); skullType = SkullType.GREEN; break; case PowerUpType.CLOSE: this.GetComponent <SpriteRenderer>().sprite = Resources.Load <Sprite>("BUFF_1"); skullType = SkullType.BLUE; break; } }
/// <summary> /// Adds the type of the skull. /// </summary> /// <param name="message">The message.</param> /// <param name="skullType">Type of the skull.</param> public static void AddSkullType(this NetworkMessage message, SkullType skullType) { message.AddByte((byte)skullType); }