예제 #1
0
 void Start()
 {
     if (PlayerPrefs.GetInt("saveGame") != 1)
     {
         //generate world
         float seed = Random.Range(-1000, 1000);
         for (int i = -270; i <= 270; i += 9)
         {
             for (int j = -270; j <= 270; j += 9)
             {
                 if (i == -270 || i == -261 || i == 270 || i == 261 || j == -270 || j == 270 || j == -261 || j == 261)
                 {
                     //map borders
                     GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("water"), new Vector3(i, -2f, j), Quaternion.identity);
                     playerInventoryScript.addTerrainToSaves(insItem);
                 }
                 else
                 {
                     float amount = Mathf.PerlinNoise(((float)i + seed) / 70, ((float)j + seed) / 70);
                     if (amount >= 0.84)
                     {
                         GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("rocky"), new Vector3(i, -1.5f, j), Quaternion.identity);
                         playerInventoryScript.addTerrainToSaves(insItem);
                     }
                     else if (amount >= 0.76f)
                     {
                         GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("desert"), new Vector3(i, -1.5f, j), Quaternion.identity);
                         playerInventoryScript.addTerrainToSaves(insItem);
                     }
                     else if (amount >= 0.60f)
                     {
                         GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("savanna"), new Vector3(i, -1.5f, j), Quaternion.identity);
                         playerInventoryScript.addTerrainToSaves(insItem);
                     }
                     else if (amount >= 0.47f)
                     {
                         GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("forest"), new Vector3(i, -1.5f, j), Quaternion.identity);
                         playerInventoryScript.addTerrainToSaves(insItem);
                     }
                     else if (amount >= 0.37f)
                     {
                         GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("plains"), new Vector3(i, -1.5f, j), Quaternion.identity);
                         playerInventoryScript.addTerrainToSaves(insItem);
                     }
                     else
                     {
                         GameObject insItem = Instantiate(playerInventoryScript.findTerrainPrefabWithName("water"), new Vector3(i, -2f, j), Quaternion.identity);
                         playerInventoryScript.addTerrainToSaves(insItem);
                     }
                 }
             }
         }
     }
     else
     {
         //load save
         SaveAndLoad.LoadPlayer(this);
     }
 }
예제 #2
0
    public void LoadPlayer()
    {
        PlayerData pData = SaveAndLoad.LoadPlayer();

        Vector3 position;

        position.x = pData.position[0];
        position.y = pData.position[1];
        position.z = pData.position[2];

        transform.position = position;

        // damit wenn man wärend einer bewegung läd nicht die bewegung weiter geht wenn man zurückgesetzt wird
        rb.velocity = new Vector2(0, 0);
    }
예제 #3
0
 // Start is called before the first frame update
 void Start()
 {
     if (SaveAndLoad.LoadPlayer() != null)
     {
         currentHighestScore = SaveAndLoad.LoadPlayer().currentHightestScore;
     }
     else
     {
         currentHighestScore = 0;
     }
     sound       = FindObjectOfType <SoundFXManager>();
     PlayerScore = 0;
     rb2d        = GetComponent <Rigidbody2D>();
     FindObjectOfType <SoundFXManager>().Play("Bike");
     animator = GetComponent <Animator>();
     print(currentHighestScore);
     GameHandler.instance.UpdateHighestScoreText(currentHighestScore);
 }
예제 #4
0
    public void LoadPlayer()
    {
        string path = Application.persistentDataPath + "player.capstone";

        if (File.Exists(path))
        {
            Debug.Log("Loading PlayerData");
            PlayerData data = SaveAndLoad.LoadPlayer();

            if (data.Levelindex == UnityEngine.SceneManagement.SceneManager.GetActiveScene().buildIndex)
            {
                var     p   = data.Position;
                Vector3 pos = new Vector3(p.x, p.y, p.z);
                transform.position = pos;
            }
        }
        else
        {
            Debug.LogWarning("No save file");
        }
    }
예제 #5
0
 public void LoadPlayer()
 {
     currentHighestScore = SaveAndLoad.LoadPlayer().currentHightestScore;
 }