예제 #1
0
 void GoToKitchen()
 {
     AudioFW.FadeAmbient("Keittiö");
     kitchenManager.EnterKitchen();
     saveLoad.Save();
 }
예제 #2
0
    public void LoadLevel(string levelID, string spawnpointID)
    {
        if (currentLevel != null)
        {
            UnloadCurrent();
        }

        //Unload previous level
        GameObject prefab = null;

        foreach (var ld in levels)
        {
            if (ld.id == levelID)
            {
                prefab = ld.prefab;
                break;
            }
        }
        // var x = levels.Where(ld => ld.id == levelID).First();
        if (prefab == null)
        {
            Debug.LogError("Level missing!" + levelID);
        }

        var level = Instantiate(prefab);

        currentLevel = level;

        var loaders = currentLevel.GetComponentsInChildren <ILevelLoad>();

        foreach (var load in loaders)
        {
            load.OnLevelLoad();
        }

        //Intialize level scripts

        var        spawns   = level.GetComponentsInChildren <PlayerSpawn>();
        GameObject waypoint = null;

        foreach (var sp in spawns)
        {
            if (sp.id == spawnpointID)
            {
                waypoint = sp.gameObject;
                break;
            }
        }
        if (waypoint == null)
        {
            Debug.LogError("Spawnpoint missing!" + spawnpointID);
        }
        currentWaypoint = spawnpointID;
        currentLevelID  = levelID;
        saveLoad.Save();
        player.transform.position = waypoint.transform.position;

        var audioId = level.GetComponentInChildren <LevelAudioEnv>();

        if (audioId != null)
        {
            AudioFW.FadeAmbient(audioId.id);
        }
    }