示例#1
0
    public void createEnemy(int playerSign, GameObject gamePlayer, int enemyCount)
    {
        if (GameObject.FindGameObjectsWithTag("enemy").Length == 0)
        {
            enemyModel.setPlayer(gamePlayer);
            enemy  = Instantiate(enemyModel.GetEnemyPrefab());
            _enemy = enemy.GetComponent <Enemy>();
            _enemy.Setup(enemyModel);
            if (enemyCount == 1)
            {
                _enemy.setLife((int)enemyModel.getBossEnemyLife());
                enemyModel.setIsBoss(true);
            }

            enemyModel.setSign(playerSign);
            gunManager = enemy.GetComponent <GunPresenter>();
            gunManager.Setup(gunModel);
            enemyRigidbody = enemy.GetComponent <Rigidbody2D>();
            enemyTransform = enemy.GetComponent <Transform>();
            int lastLayerId = enemyModel.getPlayer().GetComponent <SpriteRenderer>().sortingOrder;
            enemy.GetComponent <SpriteRenderer>().sortingOrder = lastLayerId + 2;
            enemyRigidbody.freezeRotation = true;
            enemy.transform.position      =
                GameObject.FindGameObjectsWithTag("stair2")[
                    GameObject.FindGameObjectsWithTag("stair2").Length - lastLayerId - 1].transform.position +
                new Vector3(0, (float)0.25);
            enemy.transform.position -= new Vector3(9 * enemyModel.getSign(), 0);
            if (enemyTransform.position.x > -4)
            {
                enemyModel.setFlip(true);
                flipEnemey();
            }
        }
    }