Exemple #1
0
    // Start is called before the first frame update
    void Start()
    {
        //Set information about the room
        this.roomGenerator = transform.root.GetComponent <RoomGeneration>();
        this.room          = this.roomGenerator.room;

        //Setup random generation with room seed
        //Random.InitState(this.room.Seed);

        //Spawn enemies if room has NOT BEEN CLEARED
        if (!this.room.IsCleared() && !this.room.IsSafeRoom)
        {
            GameObject enemy = SelectEnemyType();
            if (enemy != null)
            {
                GameObject instantiatedEnemy = Instantiate(enemy, transform.position, Quaternion.identity);
                instantiatedEnemy.transform.parent = this.roomGenerator.transform.Find("Layout").transform; //Put enemies under Layout so they are moved with the room when the room if flipped

                //Set references to correct character object in Enemy_Movement and Enemy_Shooting scripts
                instantiatedEnemy.GetComponent <Enemy_Movement>().Player = this.roomGenerator.playerPrefab.GetComponent <Rigidbody2D>();
                if (instantiatedEnemy.transform.childCount > 0) //Has weapon
                {
                    Enemy_Shooting gun = instantiatedEnemy.transform.GetChild(0).gameObject.GetComponent <Enemy_Shooting>();
                    if (gun)
                    {
                        gun.Player = this.roomGenerator.playerPrefab.GetComponent <Rigidbody2D>();
                    }
                }

                //Counts the number of enemies added to keep count how many are left in a room
                roomGenerator.IncreaseNumberOfEnemies();
            }
        }
    }
 void Start()
 {
     _enemy_Shooting = GameObject.FindObjectOfType <Enemy_Shooting>();
 }