From 61930cf21d3eb145df11ea2b719ae7be66c56d24 Mon Sep 17 00:00:00 2001
From: miepzerino <o.skotnik@gmail.com>
Date: Tue, 19 Dec 2023 02:38:48 +0000
Subject: [PATCH] Added save/load game

---
 Assets/Scripts/PlayerController.cs |   17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs
index 7d13b2e..dc4a8ac 100644
--- a/Assets/Scripts/PlayerController.cs
+++ b/Assets/Scripts/PlayerController.cs
@@ -1,3 +1,4 @@
+using Assets.Scripts.Helpers;
 using System;
 using System.ComponentModel.Design;
 using UnityEngine;
@@ -12,12 +13,12 @@
     private float maxFallSpeedCurrent = 0f;
     Vector2 moveInput;
 
-    Rigidbody2D rb;
+    public Rigidbody2D rb;
     Animator animator;
     Animator animator_rotor;
     public GameObject rotorGO;
     TouchingDirections touchingDirections;
-    Damageable health;
+    public Damageable health;
 
     [SerializeField]
     private bool _isMoving;
@@ -63,7 +64,6 @@
     {
         get
         {
-            Debug.Log("gameIsPaused: " + PauseMenu.GameIsPaused);
             return animator.GetBool(AnimationStrings.canMove) && !PauseMenu.GameIsPaused;
         }
     }
@@ -77,6 +77,17 @@
         animator_rotor = rotorGO.GetComponent<Animator>();
         touchingDirections = GetComponent<TouchingDirections>();
         health = GetComponent<Damageable>();
+        if (SaveSystem.isGameLoaded)
+        {
+            GameObject uiManager = GameObject.Find("UIManager");
+            uiManager.GetComponent<UIManager>().GameLoaded();
+            SaveData save = SaveSystem.LoadPlayer();
+            health.MaxHealth = save.maxHealth;
+            health.Health = save.health;
+            transform.position = VectorHelper.ConvertToVector3(save.position);
+            rb.velocity = VectorHelper.ConvertToVector2(save.velocity);
+            SaveSystem.isGameLoaded = false;
+        }
     }
 
     private void FixedUpdate()

--
Gitblit v1.9.3