Commit fb73f6d9 authored by Michael But's avatar Michael But
Browse files

Kleine Veränderungen an SaveSystem

parent 571eea18
fileFormatVersion: 2
guid: 83b2ccd8caab22846876189bc6815151
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 45dc3cd47d608cf449e822b512001707
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
......@@ -9,7 +9,7 @@ namespace PlayerSpawnPointScript
public static PlayerSpawnPoint psp;
public static Transform startPoint;
// Start is called before the first frame update
void Start()
void Awake()
{
if (GameObject.Find("StartPoint") != null)
{
......
......@@ -5,11 +5,24 @@ using UnityEngine;
public class SavePoint : MonoBehaviour
{
private bool isUsed;
private void Start()
{
isUsed = false;
}
public void OnTriggerStay2D(Collider2D collision)
{
if (Input.GetButtonDown("Interact"))
{
SaveSystem.SavePointUpdate(this);
isUsed = true;
}
}
public bool GetIsUsed()
{
return isUsed;
}
}
......@@ -2,22 +2,24 @@ using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
[System.Serializable]
public class SavePointData
{
public float[] position;
public SavePointData(SavePoint save)
[System.Serializable]
public class SavePointData
{
position = new float[2];
position[0] = save.transform.position.x;
position[1] = save.transform.position.y;
}
public float[] position;
public SavePointData(Vector2 save)
{
position = new float[2];
position[0] = save.x;
position[1] = save.y;
public SavePointData(SavePoint save)
{
position = new float[2];
position[0] = save.transform.position.x;
position[1] = save.transform.position.y;
}
public SavePointData(Vector2 save)
{
position = new float[2];
position[0] = save.x;
position[1] = save.y;
}
}
}
......@@ -42,12 +42,20 @@ public class SaveSystem
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(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));
SavePointData data;
try
{
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));
}
catch (Exception e)
{
data = new SavePointData(new Vector2(0, 0));
}
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