From 6d7760c120d2d1c37977575e1ff894e4c676b8ac Mon Sep 17 00:00:00 2001 From: alilas2 Date: Thu, 2 Jun 2022 14:25:22 +0200 Subject: [PATCH] Added save & load scene + save & load player position functionalities --- Assembly-CSharp.csproj | 61 +++++++++--------- Assets/Scenes/CaveEntrance.unity | 92 ++++++++++++++++++++++++++- Assets/Scenes/Main Menu.unity | 27 +++++++- Assets/Scenes/SampleScene.unity | 92 ++++++++++++++++++++++++++- Assets/Scripts/ChangeScene.cs | 6 +- Assets/Scripts/PlayerPosition.cs | 41 ++++++++++++ Assets/Scripts/PlayerPosition.cs.meta | 11 ++++ Assets/Scripts/SaveController.cs | 21 ++++++ Assets/Scripts/SaveController.cs.meta | 11 ++++ UserSettings/EditorUserSettings.asset | 4 +- 10 files changed, 330 insertions(+), 36 deletions(-) create mode 100644 Assets/Scripts/PlayerPosition.cs create mode 100644 Assets/Scripts/PlayerPosition.cs.meta create mode 100644 Assets/Scripts/SaveController.cs create mode 100644 Assets/Scripts/SaveController.cs.meta diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj index cf06de42..50f63f09 100644 --- a/Assembly-CSharp.csproj +++ b/Assembly-CSharp.csproj @@ -67,6 +67,7 @@ + @@ -658,94 +659,94 @@ C:/Program Files/Unity/Hub/Editor/2020.3.32f1/Editor/Data/NetStandard/compat/2.0.0/shims/netfx/System.Xml.Serialization.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Animation.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Animation.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.InternalAPIEngineBridge.001.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.InternalAPIEngineBridge.001.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.VSCode.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.VSCode.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.PixelPerfect.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.PixelPerfect.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Tilemap.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Tilemap.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/PsdPlugin.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/PsdPlugin.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.TextMeshPro.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.TextMeshPro.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.VisualStudio.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.VisualStudio.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.Timeline.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.Timeline.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.TextMeshPro.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.TextMeshPro.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.IK.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.IK.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Sprite.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Sprite.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Psdimporter.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Psdimporter.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Path.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Path.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.InternalAPIEditorBridge.001.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.InternalAPIEditorBridge.001.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/UnityEditor.UI.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/UnityEditor.UI.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.PlasticSCM.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.PlasticSCM.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.Rider.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.Rider.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/UnityEngine.UI.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/UnityEngine.UI.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.Mathematics.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.Mathematics.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.IK.Runtime.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.IK.Runtime.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Animation.Triangle.Runtime.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Animation.Triangle.Runtime.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Animation.Runtime.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Animation.Runtime.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.PixelPerfect.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.PixelPerfect.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.Timeline.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.Timeline.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.Mathematics.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.Mathematics.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Common.Runtime.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Common.Runtime.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.SpriteShape.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.SpriteShape.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.Common.Editor.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.Common.Editor.dll - C:/Users/alicj/Desktop/newest/Scriptum/Library/ScriptAssemblies/Unity.2D.SpriteShape.Runtime.dll + C:/Users/alicj/Desktop/AnotherSaveAttempt/Scriptum/Library/ScriptAssemblies/Unity.2D.SpriteShape.Runtime.dll diff --git a/Assets/Scenes/CaveEntrance.unity b/Assets/Scenes/CaveEntrance.unity index fe9128f2..88134fd8 100644 --- a/Assets/Scenes/CaveEntrance.unity +++ b/Assets/Scenes/CaveEntrance.unity @@ -365,6 +365,7 @@ GameObject: - component: {fileID: 78203889} - component: {fileID: 78203888} - component: {fileID: 78203887} + - component: {fileID: 78203891} m_Layer: 5 m_Name: yes m_TagString: Untagged @@ -459,6 +460,30 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 + - m_Target: {fileID: 78203891} + m_TargetAssemblyTypeName: SaveController, Assembly-CSharp + m_MethodName: SaveScene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 167690946} + m_TargetAssemblyTypeName: PlayerPosition, Assembly-CSharp + m_MethodName: SavePosition + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &78203889 MonoBehaviour: m_ObjectHideFlags: 0 @@ -501,6 +526,18 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 78203885} m_CullTransparentMesh: 1 +--- !u!114 &78203891 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 78203885} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f8dbef2798cc8064f86e56d2bc02d2fa, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &90994617 GameObject: m_ObjectHideFlags: 0 @@ -23230,6 +23267,7 @@ GameObject: - component: {fileID: 167690943} - component: {fileID: 167690944} - component: {fileID: 167690945} + - component: {fileID: 167690946} m_Layer: 0 m_Name: mainCh_standing m_TagString: Player @@ -23409,6 +23447,21 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 48a2ec1fec857c946ae3ae8e69b29562, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &167690946 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 167690937} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b95333079796daa45b7ad78056d78014, type: 3} + m_Name: + m_EditorClassIdentifier: + x: 0 + y: 0 + z: 0 --- !u!1 &193431387 GameObject: m_ObjectHideFlags: 0 @@ -168235,6 +168288,7 @@ GameObject: - component: {fileID: 2070805990} - component: {fileID: 2070805989} - component: {fileID: 2070805988} + - component: {fileID: 2070805991} m_Layer: 5 m_Name: save m_TagString: Untagged @@ -168304,7 +168358,31 @@ MonoBehaviour: m_TargetGraphic: {fileID: 2070805989} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 2070805991} + m_TargetAssemblyTypeName: SaveController, Assembly-CSharp + m_MethodName: SaveScene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 167690946} + m_TargetAssemblyTypeName: PlayerPosition, Assembly-CSharp + m_MethodName: SavePosition + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &2070805989 MonoBehaviour: m_ObjectHideFlags: 0 @@ -168347,6 +168425,18 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 2070805986} m_CullTransparentMesh: 1 +--- !u!114 &2070805991 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2070805986} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f8dbef2798cc8064f86e56d2bc02d2fa, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &2145520338 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/Main Menu.unity b/Assets/Scenes/Main Menu.unity index 2e6205a0..1e0ef298 100644 --- a/Assets/Scenes/Main Menu.unity +++ b/Assets/Scenes/Main Menu.unity @@ -530,6 +530,7 @@ GameObject: - component: {fileID: 455923089} - component: {fileID: 455923088} - component: {fileID: 455923087} + - component: {fileID: 455923090} m_Layer: 5 m_Name: ContinueButton m_TagString: Untagged @@ -600,7 +601,19 @@ MonoBehaviour: m_TargetGraphic: {fileID: 455923088} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 455923090} + m_TargetAssemblyTypeName: SaveController, Assembly-CSharp + m_MethodName: LoadScene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 --- !u!114 &455923088 MonoBehaviour: m_ObjectHideFlags: 0 @@ -639,6 +652,18 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 455923085} m_CullTransparentMesh: 1 +--- !u!114 &455923090 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 455923085} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f8dbef2798cc8064f86e56d2bc02d2fa, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &502516633 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index be4de449..241324c8 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -1123,6 +1123,7 @@ GameObject: - component: {fileID: 167690938} - component: {fileID: 167690943} - component: {fileID: 167690944} + - component: {fileID: 167690946} - component: {fileID: 167690945} m_Layer: 0 m_Name: mainCh_standing @@ -1303,6 +1304,21 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 48a2ec1fec857c946ae3ae8e69b29562, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &167690946 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 167690937} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: b95333079796daa45b7ad78056d78014, type: 3} + m_Name: + m_EditorClassIdentifier: + x: 0 + y: 0 + z: 0 --- !u!1 &174581753 GameObject: m_ObjectHideFlags: 0 @@ -26818,6 +26834,7 @@ GameObject: - component: {fileID: 897697752} - component: {fileID: 897697751} - component: {fileID: 897697753} + - component: {fileID: 897697754} m_Layer: 5 m_Name: save m_TagString: Untagged @@ -26929,7 +26946,43 @@ MonoBehaviour: m_TargetGraphic: {fileID: 897697751} m_OnClick: m_PersistentCalls: - m_Calls: [] + m_Calls: + - m_Target: {fileID: 897697754} + m_TargetAssemblyTypeName: SaveController, Assembly-CSharp + m_MethodName: SaveScene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 167690946} + m_TargetAssemblyTypeName: PlayerPosition, Assembly-CSharp + m_MethodName: SavePosition + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &897697754 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 897697749} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f8dbef2798cc8064f86e56d2bc02d2fa, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1 &913447032 GameObject: m_ObjectHideFlags: 0 @@ -121422,6 +121475,7 @@ GameObject: - component: {fileID: 2146696730} - component: {fileID: 2146696733} - component: {fileID: 2146696732} + - component: {fileID: 2146696734} m_Layer: 5 m_Name: yes m_TagString: Untagged @@ -121558,6 +121612,42 @@ MonoBehaviour: m_StringArgument: m_BoolArgument: 0 m_CallState: 2 + - m_Target: {fileID: 2146696734} + m_TargetAssemblyTypeName: SaveController, Assembly-CSharp + m_MethodName: SaveScene + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 + - m_Target: {fileID: 167690946} + m_TargetAssemblyTypeName: PlayerPosition, Assembly-CSharp + m_MethodName: SavePosition + m_Mode: 1 + m_Arguments: + m_ObjectArgument: {fileID: 0} + m_ObjectArgumentAssemblyTypeName: UnityEngine.Object, UnityEngine + m_IntArgument: 0 + m_FloatArgument: 0 + m_StringArgument: + m_BoolArgument: 0 + m_CallState: 2 +--- !u!114 &2146696734 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2146696728} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: f8dbef2798cc8064f86e56d2bc02d2fa, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &9081071845975046733 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/ChangeScene.cs b/Assets/Scripts/ChangeScene.cs index 1828c47c..4a6cec57 100644 --- a/Assets/Scripts/ChangeScene.cs +++ b/Assets/Scripts/ChangeScene.cs @@ -6,16 +6,20 @@ using System; public class ChangeScene : MonoBehaviour { + float x, y, z; + public void MoveToScene(int sceneID) { SceneManager.LoadScene(sceneID); } + + public void OnCollisionEnter2D(Collision2D collision) { if(collision.gameObject.tag == "SceneTransition") { - DoorBehaviour.Instance.ScenetToMoveTo(); + DoorBehaviour.Instance.ScenetToMoveTo(); } } } diff --git a/Assets/Scripts/PlayerPosition.cs b/Assets/Scripts/PlayerPosition.cs new file mode 100644 index 00000000..d67da872 --- /dev/null +++ b/Assets/Scripts/PlayerPosition.cs @@ -0,0 +1,41 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerPosition : MonoBehaviour +{ + public float x, y, z; + + public void SavePosition() + { + x = transform.position.x; + y = transform.position.y; + z = transform.position.z; + + PlayerPrefs.SetFloat("x", x); + PlayerPrefs.SetFloat("y", y); + PlayerPrefs.SetFloat("z", z); + } + + public void LoadPosition() + { + x = PlayerPrefs.GetFloat("x"); + y = PlayerPrefs.GetFloat("y"); + z = PlayerPrefs.GetFloat("z"); + + Vector3 LoadPosition = new Vector3(x, y, z); + transform.position = LoadPosition; + } + + void Start() + { + if(PlayerPrefs.GetString("continued") == "yes") + { + LoadPosition(); + string continued = "no"; + PlayerPrefs.SetString("continued", continued); + } + } + + +} diff --git a/Assets/Scripts/PlayerPosition.cs.meta b/Assets/Scripts/PlayerPosition.cs.meta new file mode 100644 index 00000000..be4c2797 --- /dev/null +++ b/Assets/Scripts/PlayerPosition.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: b95333079796daa45b7ad78056d78014 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/SaveController.cs b/Assets/Scripts/SaveController.cs new file mode 100644 index 00000000..1c12e89e --- /dev/null +++ b/Assets/Scripts/SaveController.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class SaveController : MonoBehaviour +{ + public void SaveScene() + { + string activeScene = SceneManager.GetActiveScene().name; + PlayerPrefs.SetString("SceneSaved", activeScene); + } + + public void LoadScene() + { + string sceneToGoTo = PlayerPrefs.GetString("SceneSaved"); + SceneManager.LoadScene(sceneToGoTo); + string continued = "yes"; + PlayerPrefs.SetString("continued", continued); + } +} diff --git a/Assets/Scripts/SaveController.cs.meta b/Assets/Scripts/SaveController.cs.meta new file mode 100644 index 00000000..83fb5b4d --- /dev/null +++ b/Assets/Scripts/SaveController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f8dbef2798cc8064f86e56d2bc02d2fa +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/UserSettings/EditorUserSettings.asset b/UserSettings/EditorUserSettings.asset index 24088cda..fed7f701 100644 --- a/UserSettings/EditorUserSettings.asset +++ b/UserSettings/EditorUserSettings.asset @@ -27,10 +27,10 @@ EditorUserSettings: value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1226ece42776f7e93ffdfe flags: 0 RecentlyUsedScenePath-7: - value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d + value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 flags: 0 RecentlyUsedScenePath-8: - value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 + value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d flags: 0 RecentlyUsedScenePath-9: value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb