Commit fb0af611 authored by Michael But's avatar Michael But

SavePoint und PlayerSpawnPoint Script erstellt und ist Funktiontüchtig.

parent d636cd6a
fileFormatVersion: 2
guid: 29c3b47bb1f689d40953870d9f90e2c4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
......@@ -54,7 +54,7 @@ public class MovementController : MonoBehaviour {
m_TempJumpCount = m_MaxJumpCount;
if (!wasGrounded)
OnLandEvent.Invoke ();
Debug.Log(m_Grounded);
//Debug.Log(m_Grounded);
}
}
}
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace PlayerSpawnPointScript
{
public class PlayerSpawnPoint : MonoBehaviour
{
public static PlayerSpawnPoint psp;
public static Transform startPoint;
// Start is called before the first frame update
void Start()
{
if (GameObject.Find("StartPoint") != null)
{
startPoint = GameObject.Find("StartPoint").transform;
}
SetPlayerPosition();
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.N))
{
SaveSystem.NewGame();
}
if (Input.GetKeyDown(KeyCode.O))
{
SetPlayerPosition();
}
}
private void SetPlayerPosition()
{
SavePointData savePosition = SaveSystem.LoadSavePoint();
transform.position = new Vector3(savePosition.position[0], savePosition.position[1], 0);
}
}
}
fileFormatVersion: 2
guid: c55e49070d8a526499f890e88caa37a2
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -3,6 +3,7 @@ using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine;
using UnityEngine.SceneManagement;
using PlayerSpawnPointScript;
public class SaveSystem
......@@ -10,7 +11,7 @@ public class SaveSystem
public static void SavePointUpdate(SavePoint save)
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/SP.txt";
string path = Application.persistentDataPath + "/SP.txt";
FileStream stream = new FileStream(path, FileMode.Create);
SavePointData data = new SavePointData(save);
......@@ -35,18 +36,18 @@ public class SaveSystem
}
else
{
Debug.LogError("WuWu");
return null;
}
}
public static void NewGame(Vector2 vec)
public static void NewGame()
{
BinaryFormatter formatter = new BinaryFormatter();
string path = Application.persistentDataPath + "/SP.txt";
FileStream stream = new FileStream(path, FileMode.Create);
SavePointData data = new SavePointData(vec);
SavePointData data = new SavePointData(new Vector2(PlayerSpawnPointScript.PlayerSpawnPoint.startPoint.transform.position.x, PlayerSpawnPointScript.PlayerSpawnPoint.startPoint.transform.position.y));
//SavePointData data = new SavePointData(new Vector2(GameObject.Find("StartPoint").transform.position.x, GameObject.Find("StartPoint").transform.position.y));
formatter.Serialize(stream, data);
stream.Close();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment