Exemplo n.º 1
0
    public void RpcSpawnEnemy(Vector3 _pos, Quaternion _rotate, uint _targetId)
    {
        if (_targetId == MultiplayerCtrl.getLocalNetId()) //代表是自己產生的敵人,不再重複生成
        {
            return;
        }
        if (EnemyGenerator.enemys.Count == SingleObj <EnemyGenerator> .obj.enemyMaxCount)     //取得client獨立的怪物產生器,檢查怪物是否超過max數量
        {
            var delEnemy = EnemyGenerator.enemys[0];
            EnemyGenerator.enemys.RemoveAt(0);
            Destroy(delEnemy.gameObject);                         //移除最早出現的敵人
        }
        var spawnEnemy = Instantiate(enemyPrefab, _pos, _rotate); //client生成敵人,新敵人加入Queue中

        EnemyGenerator.enemys.Add(spawnEnemy.GetComponent <Enemy>());
        GameObject.Find("CAsDebugText").GetComponent <UnityEngine.UI.Text>().text += "enemy = " + EnemyGenerator.enemys.IndexOf(spawnEnemy.GetComponent <Enemy>()) + "\n";
        spawnEnemy.GetComponent <EnemyMultiplayerCtrl>().targetId = _targetId;
    }
Exemplo n.º 2
0
    public GameObject createEnemy(Vector3 pos)
    {
        GameObject enemy = null;

        if (FindObjectsOfType <Enemy>().Length < enemyMaxCount)
        {
            enemy = Instantiate(enemyPrefab, pos, Quaternion.identity);
        }
        else
        {
            var delEnemy = enemys[0];
            enemys.RemoveAt(0);
            Destroy(delEnemy.gameObject);  //移除最早出現的敵人
            enemy = Instantiate(enemyPrefab, pos, Quaternion.identity);
        }

        enemy.GetComponent <EnemyMultiplayerCtrl>().targetId = MultiplayerCtrl.getLocalNetId();
        return(enemy);
    }