void spawnAir(float pos, float topBound, float bottomBound) { float spawnPlace = UnityEngine.Random.Range(bottomBound, topBound); Vector3 spawnPos = new Vector3(pos, spawnPlace, 0); float angle = PublicFunctions.FindAngle((spawnPos - GameObject.FindWithTag("Tower").transform.position).normalized.x, (spawnPos - GameObject.FindWithTag("Tower").transform.position).normalized.y); Instantiate(toSpawn, new Vector3(pos, spawnPlace, 0), Quaternion.Euler(0, 0, angle + 90)); }
void SpawnMinion() { Vector3 spawnPos = new Vector3(gameObject.transform.position.x, Random.Range(-3, 5), 0); float angle = PublicFunctions.FindAngle((spawnPos - target.transform.position).normalized.x, (spawnPos - target.transform.position).normalized.y); Instantiate(minion, spawnPos, Quaternion.Euler(0, 0, angle + 90)); minionSpawn += difference.magnitude * 0.15f; }
// Update is called once per frame void Update() { if (health <= 0) { gameObject.SetActive(false); } Vector3 player = GameObject.FindWithTag("Player").transform.position; Vector3 difference = (player - gameObject.transform.position).normalized; int offset = 135; //Compensates for angle offset transform.position = master.transform.position; transform.rotation = Quaternion.Euler(0, 0, PublicFunctions.FindAngle(difference.x, difference.y) + offset); //Sets rotation to face player in 2D PublicFunctions.PhaseThruTag(gameObject, new string[] { "Enemy", "Danger" }); //Phase through objects labeled as enemies or dangerous }
// Update is called once per frame void Update() { CommonEnemy norm = gameObject.GetComponent <CommonEnemy>(); Vector3 Angle = (norm.player.position - gameObject.transform.position).normalized; if (fireTime > 0) { fireTime -= Time.deltaTime; }//Recharge firing if (norm.difference <= range & fireTime <= 0) { Instantiate(projectile, gameObject.transform.position, Quaternion.Euler(0, 0, PublicFunctions.FindAngle(Angle.x, Angle.y))); fireTime += 1; }//Fire if player is in range and if firing is ready if (norm.difference > 50) { transform.Translate(new Vector3(0, 0, 0)); } else { if (norm.difference > range * 0.7) { transform.Translate(norm.direction * Time.deltaTime * norm.speed); } else if (norm.difference < range * 0.7) { transform.Translate(-norm.direction * Time.deltaTime * norm.speed); } }//Move to player if it's at a certain range. Back up if player's too close }