void SpawnEnemy() { randInt = Random.Range(0, 4); if (randInt == 0 && north) { spawnPosition = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + 1, 0.0f); currentSpawnCount++; } else if (randInt == 1 && east) { spawnPosition = new Vector3(this.gameObject.transform.position.x + 1, this.gameObject.transform.position.y, 0.0f); currentSpawnCount++; } else if (randInt == 2 && west) { spawnPosition = new Vector3(this.gameObject.transform.position.x - 1, this.gameObject.transform.position.y, 0.0f); currentSpawnCount++; } else if (randInt == 3 && south) { spawnPosition = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y - 1, 0.0f); currentSpawnCount++; } GameObject summonedMonster = null; //null check if (enemy) { summonedMonster = (GameObject)Instantiate(enemy, spawnPosition, spawnRotation); //null check if (summonedMonster && this) { if (summonedMonster.GetComponent <GenericMonsterBehaviour>()) { summonedMonster.GetComponent <GenericMonsterBehaviour>().spawner = this; } } spawnedMonsters.Add(summonedMonster); PathFindingModule monsterPathFinding = summonedMonster.GetComponentInChildren <PathFindingModule>(); monsterPathFinding.parameters.tileMap = tileMap; monsterPathFinding.parameters.target = targetObj; monsterPathFinding.parameters.useRoomBoundary = useRoomBoundary; // Activate monster summonedMonster.GetComponent <MonsterBehaviourAbstractFSM>().StartAI(); } coolingDown = true; }
protected void Retarget(GameObject newPathFindingTarget) { // Try to find path finding module on target of taunt PathFindingModule pathFinding = affectedTarget.GetComponentInChildren <PathFindingModule>(); if (pathFinding) { // Save the original target originalTarget = pathFinding.parameters.target; // Change the target to a new one pathFinding.parameters.target = newPathFindingTarget; // Have pathfinding refresh its path pathFinding.RefreshPath(); } }
public void Summon() { int randInt = UnityEngine.Random.Range(0, 4); Vector3 spawnPosition = Vector3.zero; if (randInt == 1) { spawnPosition = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y + 1, 0.0f); } else if (randInt == 2) { spawnPosition = new Vector3(this.gameObject.transform.position.x + 1, this.gameObject.transform.position.y, 0.0f); } else if (randInt == 3) { spawnPosition = new Vector3(this.gameObject.transform.position.x - 1, this.gameObject.transform.position.y, 0.0f); } else { spawnPosition = new Vector3(this.gameObject.transform.position.x, this.gameObject.transform.position.y - 1, 0.0f); } GameObject summonedMonster = (GameObject)Instantiate(parameters.summonedGameObject, spawnPosition, Quaternion.identity); // Set tilemap and target in summoned monster PathFindingModule monsterPathFinding = summonedMonster.GetComponentInChildren <PathFindingModule>(); monsterPathFinding.parameters.tileMap = parameters.tileMap; monsterPathFinding.parameters.target = parameters.target; summons.Add(summonedMonster); spawnTimeReady = false; // Activate monster summonedMonster.GetComponent <MonsterBehaviourAbstractFSM>().StartAI(); }
IEnumerator killWindSlimeCD(Collider2D other) { canKillWindSlime = false; PathFindingModule windMonsterPathFinding = other.gameObject.GetComponentInChildren <PathFindingModule>(); spawnPosition = new Vector3(other.gameObject.transform.position.x, other.gameObject.transform.position.y + 1, 0.0f); GameObject littleMonster = (GameObject)Instantiate(littleSlime, spawnPosition, spawnRotation); //other.gameObject.GetComponent<WindMonsterBehaviour>().list.Add(newLilSlime); PathFindingModule littleMonsterPathFinding = littleMonster.GetComponentInChildren <PathFindingModule>(); littleMonsterPathFinding.parameters.tileMap = windMonsterPathFinding.parameters.tileMap; littleMonsterPathFinding.parameters.target = windMonsterPathFinding.parameters.target; /* * spawnPosition = new Vector3(other.gameObject.transform.position.x + 1, other.gameObject.transform.position.y, 0.0f); * GameObject newLilSlime2 = (GameObject)Instantiate(littleSlime, spawnPosition, spawnRotation); * newLilSlime2.GetComponent<LittleWindSlime>().tileMap = other.gameObject.GetComponent<WindSlime>().tileMap; * newLilSlime2.GetComponent<LittleWindSlime>().targetObject = other.gameObject.GetComponent<WindSlime>().targetObject; * * spawnPosition = new Vector3(other.gameObject.transform.position.x, other.gameObject.transform.position.y - 1, 0.0f); * GameObject newLilSlime3 = (GameObject)Instantiate(littleSlime, spawnPosition, spawnRotation); * newLilSlime3.GetComponent<LittleWindSlime>().tileMap = other.gameObject.GetComponent<WindSlime>().tileMap; * newLilSlime3.GetComponent<LittleWindSlime>().targetObject = other.gameObject.GetComponent<WindSlime>().targetObject; * * spawnPosition = new Vector3(other.gameObject.transform.position.x - 1, other.gameObject.transform.position.y, 0.0f); * GameObject newLilSlime4 = (GameObject)Instantiate(littleSlime, spawnPosition, spawnRotation); * newLilSlime4.GetComponent<LittleWindSlime>().tileMap = other.gameObject.GetComponent<WindSlime>().tileMap; * newLilSlime4.GetComponent<LittleWindSlime>().targetObject = other.gameObject.GetComponent<WindSlime>().targetObject; */ Destroy(other.gameObject); yield return(new WaitForSeconds(1.0f)); canKillWindSlime = true; }
// Update is called once per frame protected override void Update () { base.Update(); if (state == BossState.SpawningRocks) { animator.SetInteger("State", 0); SpawnRocks(); state = BossState.SpawningMonsters; } if (state == BossState.SpawningMonsters) { animator.SetInteger("State", 0); framesInState = 0; int integerDirection = UnityEngine.Random.Range(0, 4); int position; Vector3 newPosition; if (integerDirection == 0) { direction = Globals.Direction.South; position = UnityEngine.Random.Range(-4, 4); newPosition = new Vector3(position, 4.5f, 0.0f); animator.SetInteger("Direction", 0); } else if (integerDirection == 1) { direction = Globals.Direction.West; position = UnityEngine.Random.Range(-3, 3); newPosition = new Vector3(5.5f, position, 0.0f); animator.SetInteger("Direction", 2); } else if (integerDirection == 2) { direction = Globals.Direction.North; position = UnityEngine.Random.Range(-4, 4); newPosition = new Vector3(position, -4.5f, 0.0f); animator.SetInteger("Direction", 1); } else { direction = Globals.Direction.East; position = UnityEngine.Random.Range(-3, 3); newPosition = new Vector3(-5.5f, position, 0.0f); animator.SetInteger("Direction", 3); } // TODO: these slimes need to have their targeting and tilemap setup if (!spawnedMonster1) { spawnedMonster1 = (GameObject)Instantiate(spawnedMonster, new Vector3(-3, 0, 0), Quaternion.identity); PathFindingModule monsterPathFinding = spawnedMonster1.GetComponentInChildren<PathFindingModule>(); monsterPathFinding.parameters.tileMap = Globals.tileMap; monsterPathFinding.parameters.target = Globals.player.gameObject; } if (!spawnedMonster2) { spawnedMonster2 = (GameObject)Instantiate(spawnedMonster, new Vector3(3, 0, 0), Quaternion.identity); PathFindingModule monsterPathFinding = spawnedMonster2.GetComponentInChildren<PathFindingModule>(); monsterPathFinding.parameters.tileMap = Globals.tileMap; monsterPathFinding.parameters.target = Globals.player.gameObject; } this.transform.position = newPosition; state = BossState.Idle; } if (state == BossState.Idle) { framesInState++; if (framesInState > idleFrames) { //isInvulnerable = false; base.makeVulnerable(); framesInState = 0; animator.SetInteger("State", 1); state = BossState.Inhaling; } } if (state == BossState.Inhaling) { framesInState++; if (framesInState > inhalingFrames) { //isInvulnerable = true; base.makeInvulnerable(); framesInState = 0; animator.SetInteger("State", 2); state = BossState.Blowing; } } if (state == BossState.Blowing) { BlowRocks(); framesInState++; if (framesInState > blowingFrames) { DestroyRocks(); framesInState = 0; animator.SetInteger("State", 0); state = BossState.SpawningRocks; } } if (state == BossState.Damaged) { framesInState++; if (framesInState > damagedFrames) { DestroyRocks(); framesInState = 0; animator.SetInteger("State", 0); state = BossState.SpawningRocks; } } }