예제 #1
0
    GameObject SpawnBot(
        SpawnPointRuntimeSet spawns,
        NamedPrefab namedPrefab,
        Vector3 lookAt,
        bool player
        )
    {
        var spawnPoint = spawns.PickRandom();
        var rotation   = Quaternion.LookRotation(lookAt - spawnPoint.transform.position);
        var botGo      = Object.Instantiate(namedPrefab.prefab, spawnPoint.transform.position + namedPrefab.offset, rotation);

        botGo.name = namedPrefab.name;
        var health = botGo.GetComponent <BotHealth>();

        if (health != null)
        {
            health.onDeath.AddListener(OnBotDeath);
        }

        // add new bot to list of active bots
        activeBots.Add(botGo.GetComponent <BotBuilder>());

        // add AI script, disable controls
        BotBrain brain;

        if (player)
        {
            brain = botGo.AddComponent <HumanController>();
            gameEventChannel.Raise(GameRecord.GamePlayerDeclared(botGo));
        }
        else
        {
            brain = botGo.AddComponent <AIController>();
            gameEventChannel.Raise(GameRecord.GameEnemyDeclared(botGo));
            ((AIController)brain).AssignConfig(defaultAIConfig);
            ((AIController)brain).TargetPlayer();
        }
        aiControllers.Add(brain);
        brain.DisableControls();

        // change color of bot
        var materialDistributor = botGo.GetComponent <MaterialDistributor>();

        if (materialDistributor != null)
        {
            materialDistributor.SetMaterials((player) ? MaterialTag.Player : MaterialTag.Enemy);
        }

        return(botGo);
    }
예제 #2
0
    GameObject SpawnHazard(
        SpawnPointRuntimeSet spawns,
        NamedPrefab namedPrefab
        )
    {
        var spawnPoint = spawns.PickRandom();

        if (namedPrefab.prefab != null)
        {
            var hazardGo = Object.Instantiate(namedPrefab.prefab, spawnPoint.transform.position + namedPrefab.offset, Quaternion.identity);
            hazardGo.name = namedPrefab.name;
            var brain = hazardGo.GetComponent <BotBrain>();
            if (brain != null)
            {
                brain.DisableControls();
                aiControllers.Add(brain);
            }
            return(hazardGo);
        }
        else
        {
            return(null);
        }
    }