protected IEnumerator MetCannon() { do { yield return(null); } while (Mathf.Abs(GameManager.playerPosition.x - transform.position.x) > 80.0f); anim.Play("MetCannonShielded"); yield return(new WaitForSeconds(0.2f)); // Waits for the player to get close in the X axis. while (Mathf.Abs(GameManager.playerPosition.x - transform.position.x) <= 112.0f) { // Turns to face the player. if ((GameManager.playerPosition.x - transform.position.x) * transform.right.x > 0) { anim.Play("MetCannonTurn"); yield return(new WaitForSeconds(0.1f)); anim.Play("MetCannonShielded"); LookAtPlayer(); } // Waits for the player to come in line of the cannon to shoot. if (Mathf.Abs(GameManager.playerPosition.y - transform.position.y) < 16) { anim.Play("MetCannonAwake"); shielded = false; yield return(new WaitForSeconds(0.1f)); anim.Play("MetCannonShoot"); // Shoots a big shot. EnWp_Shot shot = ((GameObject)Instantiate(Resources.Load("Prefabs/Enemies/En_BigShot1"))).GetComponent <EnWp_Shot>(); shot.transform.position = transform.position + center + Vector3.forward; shot.direction = transform.right * (transform.localScale.x > 0 ? -1 : 1); shot.speed = 150.0f; yield return(new WaitForSeconds(0.75f)); break; } yield return(null); } // Resets and shields the Met. shielded = true; anim.Play("MetCannonIdle"); waitDownTime = 1.0f; }
public virtual GameObject Shoot(Vector2 shootPosition, Vector2 shotDirection, float shotDamage, float shotSpeed = 200, GameObject obj = null) { // This script is supposed to work with a GameObject containing a EnWp_Shot component or one that derives from it, // but can be used with any GameObject. // If there isn't a GameObject given, the the default bullet will be assigned. if (obj == null) { obj = (GameObject)Resources.Load("Prefabs/Enemies/En_Shot", typeof(GameObject)); } // Makes a new instance of the bullet in the scene, then moves it and rotates it accordingly. GameObject o = Instantiate(obj); o.transform.position = shootPosition; if (shotDirection.sqrMagnitude > 0) { o.transform.rotation = Quaternion.AngleAxis(Mathf.Atan2(shotDirection.y, shotDirection.x), Vector3.forward); } // Checks if there is a EnWp_Shot component, and changes its properties accordingly. EnWp_Shot shot = o.GetComponent <EnWp_Shot>(); if (shot != null) { if (shotDirection.sqrMagnitude > 0) { shot.direction = shotDirection.normalized; } shot.damage = shotDamage; shot.speed = shotSpeed; } // Since bullets shouldn't have gravity by default, the gravity is set to 0. if (o.GetComponent <Rigidbody2D>() != null) { o.GetComponent <Rigidbody2D>().gravityScale = 0.0f; } return(o); }