Added enemy status, health status and NPC dialogue status to save & load game system

This commit is contained in:
alilas2 2022-06-15 16:32:14 +02:00
parent 8b81da0d32
commit 7223cebdd9
9 changed files with 87 additions and 15 deletions

View File

@ -4,5 +4,23 @@ using UnityEngine;
public class NPCType : MonoBehaviour public class NPCType : MonoBehaviour
{ {
public GameObject lumberjack;
public int isQuest; public int isQuest;
public string name;
void Start()
{
NPCDialogue npcdialogue = lumberjack.GetComponent<NPCDialogue>();
name = npcdialogue.name;
isQuest = PlayerPrefs.GetInt(name);
npcdialogue.isQuest = isQuest;
}
void Update()
{
NPCDialogue npcdialogue = lumberjack.GetComponent<NPCDialogue>();
isQuest = npcdialogue.isQuest;
PlayerPrefs.SetInt(name, isQuest);
}
} }

View File

@ -12,5 +12,17 @@ public class NewGame : MonoBehaviour
PlayerPrefs.SetString("pickaxe1", pickaxe1); PlayerPrefs.SetString("pickaxe1", pickaxe1);
string name = "none"; string name = "none";
PlayerPrefs.SetString("name", name); PlayerPrefs.SetString("name", name);
int isQuest = 1;
PlayerPrefs.SetInt("lumberjack", isQuest);
int isKilled = 0;
PlayerPrefs.SetInt("bat0", isKilled);
PlayerPrefs.SetInt("bat1", isKilled);
PlayerPrefs.SetInt("skeleton0", isKilled);
PlayerPrefs.SetInt("slime0", isKilled);
PlayerPrefs.SetInt("slime1", isKilled);
float health = 10.0f;
PlayerPrefs.SetFloat("health", health);
} }
} }

View File

@ -54488,6 +54488,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 81223f4044aba464faed4fa279d6c9b1, type: 3} m_Script: {fileID: 11500000, guid: 81223f4044aba464faed4fa279d6c9b1, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
name: lumberjack
nameText: {fileID: 749129730} nameText: {fileID: 749129730}
nameText1: {fileID: 1534487215} nameText1: {fileID: 1534487215}
dialogueText: {fileID: 2145520340} dialogueText: {fileID: 2145520340}
@ -54538,7 +54539,9 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 1e949be2a455e78458dc423198660daf, type: 3} m_Script: {fileID: 11500000, guid: 1e949be2a455e78458dc423198660daf, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
lumberjack: {fileID: 551619101}
isQuest: 1 isQuest: 1
name:
--- !u!1 &589833388 --- !u!1 &589833388
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -367,7 +367,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 3 moveSpeed: 3
enemyName: enemyName: bat1
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 1 baseAttack: 1
@ -383,6 +383,7 @@ MonoBehaviour:
player: {fileID: 167690937} player: {fileID: 167690937}
thrust: 5 thrust: 5
knockTime: 0.2 knockTime: 0.2
isKilled: 0
--- !u!1 &23852502 --- !u!1 &23852502
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -683,7 +684,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 6 moveSpeed: 6
enemyName: enemyName: skeleton0
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 0 baseAttack: 0
@ -694,6 +695,7 @@ MonoBehaviour:
currentGoal: {fileID: 0} currentGoal: {fileID: 0}
roundingDistance: 0 roundingDistance: 0
anim: {fileID: 0} anim: {fileID: 0}
isKilled: 0
--- !u!95 &68076404 --- !u!95 &68076404
Animator: Animator:
serializedVersion: 3 serializedVersion: 3
@ -773,7 +775,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 2.5 moveSpeed: 2.5
enemyName: enemyName: skeleton0
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 2 baseAttack: 2
@ -789,6 +791,7 @@ MonoBehaviour:
player: {fileID: 167690937} player: {fileID: 167690937}
thrust: 5 thrust: 5
knockTime: 0.2 knockTime: 0.2
isKilled: 0
--- !u!1 &84519187 --- !u!1 &84519187
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2017,7 +2020,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 0 moveSpeed: 0
enemyName: enemyName: bat0
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 1 baseAttack: 1
@ -2028,6 +2031,7 @@ MonoBehaviour:
currentGoal: {fileID: 0} currentGoal: {fileID: 0}
roundingDistance: 0 roundingDistance: 0
anim: {fileID: 0} anim: {fileID: 0}
isKilled: 0
--- !u!50 &242009515 --- !u!50 &242009515
Rigidbody2D: Rigidbody2D:
serializedVersion: 4 serializedVersion: 4
@ -2088,7 +2092,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 2.8 moveSpeed: 2.8
enemyName: enemyName: bat0
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 1 baseAttack: 1
@ -2104,6 +2108,7 @@ MonoBehaviour:
player: {fileID: 167690937} player: {fileID: 167690937}
thrust: 5 thrust: 5
knockTime: 0.2 knockTime: 0.2
isKilled: 0
--- !u!1 &246924466 --- !u!1 &246924466
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -31372,7 +31377,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 2 moveSpeed: 2
enemyName: enemyName: slime0
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 0.5 baseAttack: 0.5
@ -31388,6 +31393,7 @@ MonoBehaviour:
player: {fileID: 167690937} player: {fileID: 167690937}
thrust: 5 thrust: 5
knockTime: 0.2 knockTime: 0.2
isKilled: 0
--- !u!1 &652174079 --- !u!1 &652174079
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -31658,7 +31664,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
moveSpeed: 1.2 moveSpeed: 1.2
enemyName: enemyName: slime1
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2} maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0 health: 0
baseAttack: 0.5 baseAttack: 0.5
@ -31674,6 +31680,7 @@ MonoBehaviour:
player: {fileID: 167690937} player: {fileID: 167690937}
thrust: 5 thrust: 5
knockTime: 0.2 knockTime: 0.2
isKilled: 0
--- !u!1 &683424791 --- !u!1 &683424791
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -138797,6 +138804,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 81223f4044aba464faed4fa279d6c9b1, type: 3} m_Script: {fileID: 11500000, guid: 81223f4044aba464faed4fa279d6c9b1, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
name:
nameText: {fileID: 1081484092} nameText: {fileID: 1081484092}
nameText1: {fileID: 1081484092} nameText1: {fileID: 1081484092}
dialogueText: {fileID: 1736078185} dialogueText: {fileID: 1736078185}

View File

@ -28,10 +28,19 @@ public class FollowingEnemy : Enemy
public float thrust; public float thrust;
public float knockTime; public float knockTime;
public int isKilled;
//isKilled = 0 - mob ALIVE
//isKilled = 1 - mob DEAD
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
isKilled = PlayerPrefs.GetInt(enemyName);
if (isKilled == 1)
{
gameObject.SetActive(false);
}
myRigidbody = GetComponent<Rigidbody2D>(); myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
target = GameObject.FindWithTag("Player").transform; target = GameObject.FindWithTag("Player").transform;
@ -75,6 +84,11 @@ public class FollowingEnemy : Enemy
TakeKnockback(); TakeKnockback();
} }
} }
if (gameObject.active == false)
{
isKilled = 1;
PlayerPrefs.SetInt(enemyName, isKilled);
}
} }

View File

@ -13,9 +13,18 @@ public class PatrollingEnemy : Enemy
//public Transform target; //public Transform target;
public Animator anim; public Animator anim;
public int isKilled;
//isKilled = 0 - mob ALIVE
//isKilled = 1 - mob DEAD
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
isKilled = PlayerPrefs.GetInt(enemyName);
if(isKilled == 1)
{
gameObject.SetActive(false);
}
myRigidbody = GetComponent<Rigidbody2D>(); myRigidbody = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator>(); anim = GetComponent<Animator>();
} }
@ -33,6 +42,11 @@ public class PatrollingEnemy : Enemy
{ {
changeGoal(); changeGoal();
} }
if(gameObject.active == false)
{
isKilled = 1;
PlayerPrefs.SetInt(enemyName, isKilled);
}
} }
private void changeGoal() private void changeGoal()

View File

@ -5,7 +5,7 @@ using UnityEngine.UI;
public class NPCDialogue : MonoBehaviour public class NPCDialogue : MonoBehaviour
{ {
public string name;
public Text nameText; public Text nameText;
public Text nameText1; public Text nameText1;
public Text dialogueText; public Text dialogueText;

View File

@ -34,8 +34,9 @@ public class Player : MonoBehaviour
{ {
rb = gameObject.GetComponent<Rigidbody2D>(); rb = gameObject.GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>(); myAnimator = GetComponent<Animator>();
currentHealth = maxHealth.initialValue; currentHealth = PlayerPrefs.GetFloat("health");
healthBar.SetMaxHealth(maxHealth.initialValue); healthBar.SetMaxHealth(maxHealth.initialValue);
healthBar.SetHealth(currentHealth);
walkSpeed = 4f; walkSpeed = 4f;
} }
@ -144,6 +145,8 @@ public class Player : MonoBehaviour
} }
} }
} }
PlayerPrefs.SetFloat("health", currentHealth);
//} //}
HandleInput(); HandleInput();

View File

@ -24,16 +24,16 @@ EditorUserSettings:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25 value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25
flags: 0 flags: 0
RecentlyUsedScenePath-6: RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
flags: 0 flags: 0
RecentlyUsedScenePath-8: RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0 flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
flags: 0
RecentlyUsedScenePath-9: RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021 value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0 flags: 0
vcSharedLogLevel: vcSharedLogLevel:
value: 0d5e400f0650 value: 0d5e400f0650