Пример #1
0
    IEnumerator spawnTimer(float time)
    {
        yield return(new WaitForSeconds(time));

        EnemyPrefab enemy = enemies[Random.Range(0, enemies.Length - 1)];

        Instantiate(enemy.prefab,
                    RandomVec.getRandomPosition(enemy.positionConstraints, _player.transform.position, enemy.minPlayerDistance),
                    Quaternion.Euler(RandomVec.getRandomVector(enemy.rotationConstraints)));
    }
Пример #2
0
    // Start is called before the first frame update
    void Start()
    {
        surface = GetComponent <NavMeshSurface>();
        #if !UNITY_EDITOR
        //lock mouse
        Cursor.lockState = CursorLockMode.Locked;
        Cursor.visible   = false;
        #endif

        surface = GetComponent <NavMeshSurface>();

        //spawn player
        _player = Instantiate(player.prefab,
                              RandomVec.getRandomVector(player.positionConstraints),
                              Quaternion.Euler(RandomVec.getRandomVector(player.rotationConstraints)));
        _playerHealth = _player.GetComponent <CharacterHealth>();

        //populate scene
        foreach (SceneObject t in sceneData.objects)
        {
            for (int i = 0; i < t.count; i++)
            {
                Instantiate(t.prefab,
                            RandomVec.getRandomPosition(t.positionOverride ? t.positionConstraints : sceneData.positionConstraints, _player.transform.position, sceneData.playerAvoidRadius),
                            Quaternion.Euler(RandomVec.getRandomVector(t.rotationOverride ? t.rotationConstraints : sceneData.rotationConstraints)),
                            sceneData.parent);
            }
        }
        surface.BuildNavMesh();

        //spawn enemies
        foreach (EnemyPrefab enemy in enemies)
        {
            for (int i = 0; i < enemy.spawnCount; i++)
            {
                Instantiate(enemy.prefab,
                            RandomVec.getRandomPosition(enemy.positionConstraints, _player.transform.position, enemy.minPlayerDistance),
                            Quaternion.Euler(RandomVec.getRandomVector(enemy.rotationConstraints)));
            }
        }

        //create hud after player
        Instantiate(hudPrefab);

        lastUpdate = Time.time;
    }