public override void doAction() { //Finds the player that is being followed GameObject player = GameObject.FindGameObjectWithTag("Player"); //Creates the Follower, position of follower GameObject spawnFollower = (GameObject)Resources.Load("Prefabs/Player/Follower"); Vector3 spawnPos = player.transform.position; GameObject newFollower = (GameObject)Instantiate(spawnFollower, spawnPos, Quaternion.identity); //set the leader of follower FollowerBehavior fBeh = newFollower.GetComponent <FollowerBehavior> (); fBeh.leader = player.transform; }
private void spawnPair() { GameObject player = GameObject.FindGameObjectWithTag("Player"); if (player == null) { return; } GameObject spawningShip = (GameObject)Resources.Load("Prefabs/Enemies/PurpleEnemy"); Vector3 spawnPos = Vector3.zero; //If there's a player, we need to make sure the enemies won't spawn in the player's fov. float xVal = Random.Range(spawnBound.xMin, spawnBound.xMax); while (player.transform.position.x - xVal < 5.5 && player.transform.position.x - xVal > -5.5) { //get a new xval xVal = Random.Range(spawnBound.xMin, spawnBound.xMax); } float zVal = Random.Range(spawnBound.zMin, spawnBound.zMax); while (player.transform.position.z - zVal < 5.5 && player.transform.position.z - zVal > -5.5) { //get a new zval zVal = Random.Range(spawnBound.zMin, spawnBound.zMax); } spawnPos = new Vector3( xVal, 0.0f, zVal); GameObject newEnemy = (GameObject)Instantiate(spawningShip, spawnPos, Quaternion.identity); //Make sure they track the player! newEnemy.GetComponent <TrackTo> ().target = player.transform; //The follower is a lot easier to instantiate, since it will spawn next to it's parent GameObject follower = (GameObject)Resources.Load("Prefabs/Enemies/EnemyFollower"); GameObject newF = (GameObject)Instantiate(follower, spawnPos, Quaternion.identity); FollowerBehavior fBeh = newF.GetComponent <FollowerBehavior> (); fBeh.leader = newEnemy.transform; //Adds the new enemy to the radar track Hashtable addEnemyToRadar(newEnemy); }