Beispiel #1
0
    //load game
    public void Load()
    {
        PlayerData playerData = saveLoadPlayer.LoadData();

        if (playerData != null)
        {
            MapName savedMap = (MapName)playerData.map;

            //don't load if the data is for a different map
            if (savedMap == 0 || savedMap.Equals(mapName))
            {
                score = playerData.score;
                PlayerPrefs.SetInt("CurrentScore", score);

                float[] c = playerData.coords;
                coords = new Vector3(c[0], c[1], c[2]);
                player.transform.position = coords;

                var playerMove = player.GetComponent <PlayerMovement>();
                AbilityProcessor.Fetch((PlayerAbilities)playerData.abilityType, playerMove);

                ProjectileProcessor.SetProjectileName((PlayerProjectiles)playerData.projectileType);

                /*
                 * Sample Hierarchy of GameObject Tile
                 * to change the checkpoint image
                 *  Tile
                 *      -> Obstacles
                 *      -> Checkpoint1
                 *          -> CheckpointScript
                 *
                 * Process:
                 *  - Find the child gameobject using the name
                 *  - Call the ChangeState() of the child script
                 */

                //name of the loaded checkpoint
                checkpointTag = playerData.checkpointTag;

                //gets the list its children
                Transform[] childrenObj = tileObject.GetComponentsInChildren <Transform>();

                foreach (Transform obj in childrenObj)
                {
                    //if name matches with checkpointTag, change the state
                    if (obj.name == checkpointTag)
                    {
                        CheckpointScript objScript = obj.GetComponent <CheckpointScript>();
                        objScript.ForceWave();
                        break;
                    }
                }
            }
            else
            {
                Debug.Log("Data is for the different map. Data is not loaded");
            }
        }
    }