Improvements to Save & Load Game system

This commit is contained in:
alilas2 2022-06-15 19:54:44 +02:00
parent 7223cebdd9
commit 81360ff25c
14 changed files with 484 additions and 31 deletions

View File

@ -4,6 +4,10 @@ using UnityEngine;
public class BreakOre : MonoBehaviour
{
public string name;
public string name2;
public Sprite[] sprites;
private int oldSprite;
private int newSprite;
@ -11,7 +15,7 @@ public class BreakOre : MonoBehaviour
public ParticleSystem breakParticleSystem;
public bool timeToBreak = false;
public int isBroken;
void Start()
{
@ -21,13 +25,29 @@ public class BreakOre : MonoBehaviour
availableSprites.Add(i);
}
int continued = PlayerPrefs.GetInt("continued");
if (continued == 1)
{
isBroken = PlayerPrefs.GetInt(name2);
}
else
{
isBroken = PlayerPrefs.GetInt(name);
}
if (isBroken == 1)
{
gameObject.SetActive(false);
}
}
IEnumerator Timer()
{
if (timeToBreak == true)
{
isBroken = 1;
gameObject.SetActive(false);
PlayerPrefs.SetInt(name, isBroken);
}
yield return new WaitForSeconds(1);
var em = breakParticleSystem.emission;
@ -57,4 +77,9 @@ public class BreakOre : MonoBehaviour
}
}
public void SaveCheckpoint()
{
PlayerPrefs.SetInt(name2, isBroken);
}
}

View File

@ -8,12 +8,22 @@ public class NPCType : MonoBehaviour
public GameObject lumberjack;
public int isQuest;
public string name;
public string name2;
void Start()
{
NPCDialogue npcdialogue = lumberjack.GetComponent<NPCDialogue>();
name = npcdialogue.name;
isQuest = PlayerPrefs.GetInt(name);
int continued = PlayerPrefs.GetInt("continued");
if (continued == 1)
{
isQuest = PlayerPrefs.GetInt(name2);
}
else
{
isQuest = PlayerPrefs.GetInt(name);
}
npcdialogue.isQuest = isQuest;
}
@ -23,4 +33,11 @@ public class NPCType : MonoBehaviour
isQuest = npcdialogue.isQuest;
PlayerPrefs.SetInt(name, isQuest);
}
public void SaveCheckpoint()
{
NPCDialogue npcdialogue = lumberjack.GetComponent<NPCDialogue>();
isQuest = npcdialogue.isQuest;
PlayerPrefs.SetInt(name2, isQuest);
}
}

View File

@ -22,6 +22,11 @@ public class NewGame : MonoBehaviour
PlayerPrefs.SetInt("slime1", isKilled);
float health = 10.0f;
PlayerPrefs.SetFloat("health", health);
PlayerPrefs.SetInt("continued", 0);
PlayerPrefs.SetInt("rock", 0);
PlayerPrefs.SetInt("goldOre", 0);
PlayerPrefs.SetInt("pickaxe", 0);
}

View File

@ -830,6 +830,30 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 167690940}
m_TargetAssemblyTypeName: Player, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 551619109}
m_TargetAssemblyTypeName: NPCType, Assembly-CSharp
m_MethodName: SaveCheckpoint
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
@ -23907,6 +23931,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c457960c7d486d346910a6b3fa90380e, type: 3}
m_Name:
m_EditorClassIdentifier:
mainCh: {fileID: 167690937}
--- !u!1 &182783044
GameObject:
m_ObjectHideFlags: 0
@ -54542,6 +54567,7 @@ MonoBehaviour:
lumberjack: {fileID: 551619101}
isQuest: 1
name:
name2: lumberjack-S
--- !u!1 &589833388
GameObject:
m_ObjectHideFlags: 0
@ -75909,6 +75935,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
item: {fileID: 11400000, guid: 6e4f9a44bbdb0b5418932889316a45eb, type: 2}
name:
name2:
triggered: 0
isPicked: 0
--- !u!50 &712505176
Rigidbody2D:
serializedVersion: 4
@ -252667,6 +252697,30 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 167690940}
m_TargetAssemblyTypeName: Player, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 551619109}
m_TargetAssemblyTypeName: NPCType, Assembly-CSharp
m_MethodName: SaveCheckpoint
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

View File

@ -371,6 +371,7 @@ MonoBehaviour:
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0
baseAttack: 1
name2: bat1-S
target: {fileID: 0}
chaseRadius: 6
attackRadius: 0.55
@ -384,6 +385,8 @@ MonoBehaviour:
thrust: 5
knockTime: 0.2
isKilled: 0
continued: 0
isKilled2: 0
--- !u!1 &23852502
GameObject:
m_ObjectHideFlags: 0
@ -779,6 +782,7 @@ MonoBehaviour:
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0
baseAttack: 2
name2: skeleton0-S
target: {fileID: 0}
chaseRadius: 5
attackRadius: 0.5
@ -792,6 +796,8 @@ MonoBehaviour:
thrust: 5
knockTime: 0.2
isKilled: 0
continued: 0
isKilled2: 0
--- !u!1 &84519187
GameObject:
m_ObjectHideFlags: 0
@ -1556,6 +1562,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c457960c7d486d346910a6b3fa90380e, type: 3}
m_Name:
m_EditorClassIdentifier:
mainCh: {fileID: 167690937}
--- !u!114 &167690948
MonoBehaviour:
m_ObjectHideFlags: 0
@ -2096,6 +2103,7 @@ MonoBehaviour:
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0
baseAttack: 1
name2: bat0-S
target: {fileID: 0}
chaseRadius: 6
attackRadius: 0.55
@ -2109,6 +2117,8 @@ MonoBehaviour:
thrust: 5
knockTime: 0.2
isKilled: 0
continued: 0
isKilled2: 0
--- !u!1 &246924466
GameObject:
m_ObjectHideFlags: 0
@ -31035,6 +31045,10 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
item: {fileID: 11400000, guid: 5935777f7ac390a4187e03f34e7cafdd, type: 2}
name: pickaxe
name2: pickaxe-S
triggered: 0
isPicked: 0
--- !u!50 &622865438
Rigidbody2D:
serializedVersion: 4
@ -31381,6 +31395,7 @@ MonoBehaviour:
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0
baseAttack: 0.5
name2: slime0-S
target: {fileID: 0}
chaseRadius: 6
attackRadius: 0.5
@ -31394,6 +31409,8 @@ MonoBehaviour:
thrust: 5
knockTime: 0.2
isKilled: 0
continued: 0
isKilled2: 0
--- !u!1 &652174079
GameObject:
m_ObjectHideFlags: 0
@ -31668,6 +31685,7 @@ MonoBehaviour:
maxHealth: {fileID: 11400000, guid: 1a234827b90bfc24da563fbd5ffb412a, type: 2}
health: 0
baseAttack: 0.5
name2: slime1-S
target: {fileID: 0}
chaseRadius: 8
attackRadius: 0.5
@ -31681,6 +31699,8 @@ MonoBehaviour:
thrust: 5
knockTime: 0.2
isKilled: 0
continued: 0
isKilled2: 0
--- !u!1 &683424791
GameObject:
m_ObjectHideFlags: 0
@ -42082,6 +42102,8 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 6525aab418780094b945c897f66e0cb4, type: 3}
m_Name:
m_EditorClassIdentifier:
name: rock
name2: rock-S
sprites:
- {fileID: 2182001056168252113, guid: ecf31a6807f97e9488454a9c4584be91, type: 3}
- {fileID: 6561149998582627035, guid: 352b18285249a3f44a85026b80d75f52, type: 3}
@ -42284,6 +42306,114 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 242009517}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 8620312}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 68076407}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 641696208}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 682072036}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 889215477}
m_TargetAssemblyTypeName: breakable, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 1200894939}
m_TargetAssemblyTypeName: BreakOre, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 622865437}
m_TargetAssemblyTypeName: PickableController, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 167690940}
m_TargetAssemblyTypeName: Player, Assembly-CSharp
m_MethodName: SaveCheckpoint
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
@ -42986,6 +43116,7 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: c457960c7d486d346910a6b3fa90380e, type: 3}
m_Name:
m_EditorClassIdentifier:
mainCh: {fileID: 167690937}
--- !u!1 &1008082823
GameObject:
m_ObjectHideFlags: 0
@ -44048,11 +44179,14 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 221b868deecf9a94c86d5e989abeb8a8, type: 3}
m_Name:
m_EditorClassIdentifier:
name: goldOre
name2: goldOre-S
sprites:
- {fileID: -2769473736760253650, guid: 707503ddc182f7e4aad33c5e3a9a56ba, type: 3}
- {fileID: 2172676185572096100, guid: 1942087f81e48a6418d29c06a6482774, type: 3}
breakParticleSystem: {fileID: 359978803}
timeToBreak: 0
isBroken: 0
--- !u!50 &1200894940
Rigidbody2D:
serializedVersion: 4
@ -139121,6 +139255,114 @@ MonoBehaviour:
m_StringArgument:
m_BoolArgument: 0
m_CallState: 2
- m_Target: {fileID: 242009517}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 8620312}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 68076407}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 641696208}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 682072036}
m_TargetAssemblyTypeName: FollowingEnemy, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 889215477}
m_TargetAssemblyTypeName: breakable, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 1200894939}
m_TargetAssemblyTypeName: BreakOre, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 622865437}
m_TargetAssemblyTypeName: PickableController, Assembly-CSharp
m_MethodName: SaveCheckpoint
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: 167690940}
m_TargetAssemblyTypeName: Player, Assembly-CSharp
m_MethodName: SaveCheckpoint
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

View File

@ -4,6 +4,8 @@ using UnityEngine;
public class FollowingEnemy : Enemy
{
public string name2;
public Transform target;
public float chaseRadius;
public float attackRadius;
@ -32,11 +34,23 @@ public class FollowingEnemy : Enemy
//isKilled = 0 - mob ALIVE
//isKilled = 1 - mob DEAD
public int continued;
public int isKilled2;
// Start is called before the first frame update
void Start()
{
isKilled = PlayerPrefs.GetInt(enemyName);
continued = PlayerPrefs.GetInt("continued");
if (continued == 1)
{
isKilled = PlayerPrefs.GetInt(name2);
}
else
{
isKilled = PlayerPrefs.GetInt(enemyName);
}
if (isKilled == 1)
{
gameObject.SetActive(false);
@ -165,4 +179,9 @@ public class FollowingEnemy : Enemy
enemy.isKinematic = true;
}
}
public void SaveCheckpoint()
{
PlayerPrefs.SetInt(name2, isKilled);
}
}

View File

@ -6,25 +6,58 @@ using System;
public class PickableController : MonoBehaviour
{
public EquippableItem item;
public string name;
public string name2;
public bool triggered;
public int isPicked;
public void Start()
{
item.Name = gameObject.name;
string pickaxe = PlayerPrefs.GetString("pickaxe1");
if(pickaxe == "picked")
if (PlayerPrefs.GetInt("continued") == 1)
{
isPicked = PlayerPrefs.GetInt(name2);
}
else
{
isPicked = PlayerPrefs.GetInt(name);
}
if(isPicked == 1)
{
gameObject.SetActive(false);
}
}
void Update()
{
if(triggered)
{
if (Input.GetKeyDown(KeyCode.E))
{
InventoryManager.Instance.AddToInventory(this.item);
isPicked = 1;
PlayerPrefs.SetInt(name, isPicked);
gameObject.SetActive(false);
}
}
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag == "Player")
{
InventoryManager.Instance.AddToInventory(this.item);
string pickaxe = "picked";
PlayerPrefs.SetString("pickaxe1", pickaxe);
gameObject.SetActive(false);
triggered = true;
}
}
private void OnTriggerExit2D(Collider2D collision)
{
triggered = false;
}
public void SaveCheckpoint()
{
PlayerPrefs.SetInt(name2, isPicked);
}
}

View File

@ -30,6 +30,7 @@ public class NPCDialogue : MonoBehaviour
sentencesWQuest = new Queue<string>();
sentencesAQuest = new Queue<string>();
}
public void TriggerDialogue()

View File

@ -32,9 +32,17 @@ public class Player : MonoBehaviour
void Start()
{
int continued = PlayerPrefs.GetInt("continued");
if (continued == 1)
{
currentHealth = PlayerPrefs.GetFloat("health-S");
}
else
{
currentHealth = PlayerPrefs.GetFloat("health");
}
rb = gameObject.GetComponent<Rigidbody2D>();
myAnimator = GetComponent<Animator>();
currentHealth = PlayerPrefs.GetFloat("health");
healthBar.SetMaxHealth(maxHealth.initialValue);
healthBar.SetHealth(currentHealth);
walkSpeed = 4f;
@ -175,4 +183,9 @@ public class Player : MonoBehaviour
ResetValues();
}
public void SaveCheckpoint()
{
PlayerPrefs.SetFloat("health-S", currentHealth);
}
}

View File

@ -29,13 +29,18 @@ public class PlayerPosition : MonoBehaviour
void Start()
{
if(PlayerPrefs.GetString("continued") == "yes")
if (PlayerPrefs.GetInt("continued") == 1)
{
LoadPosition();
string continued = "no";
PlayerPrefs.SetString("continued", continued);
StartCoroutine(ChangeContinueValue());
}
}
private IEnumerator ChangeContinueValue()
{
yield return new WaitForSeconds(0.2f);
PlayerPrefs.SetInt("continued", 0);
}
}

View File

@ -7,11 +7,15 @@ public class RespawnScript : MonoBehaviour
{
private string currentScene;
public GameObject mainCh;
public void RespawnOnCurrentScene()
{
Scene scene = SceneManager.GetActiveScene();
currentScene = scene.name;
SceneManager.LoadScene(currentScene);
Player player = mainCh.GetComponent<Player>();
player.currentHealth = 10.0f;
}
}

View File

@ -15,7 +15,7 @@ public class SaveController : MonoBehaviour
{
string sceneToGoTo = PlayerPrefs.GetString("SceneSaved");
SceneManager.LoadScene(sceneToGoTo);
string continued = "yes";
PlayerPrefs.SetString("continued", continued);
int continued = 1;
PlayerPrefs.SetInt("continued", continued);
}
}

View File

@ -5,25 +5,51 @@ using UnityEngine;
public class breakable : MonoBehaviour
{
public string name;
public string name2;
public Sprite[] sprites;
private int oldSprite;
private int newSprite;
private List<int> availableSprites = new List<int>();
public ParticleSystem collisionParticleSystem;
public bool timeToBreak = false;
private int isBroken = 0;
void Start()
{
oldSprite = 0;
for(int i=0; i<3; i++)
{
availableSprites.Add(i);
}
int rock = PlayerPrefs.GetInt("rock");
if(rock == 0)
int continued = PlayerPrefs.GetInt("continued");
if (continued == 1)
{
isBroken = PlayerPrefs.GetInt(name2);
}
else
{
isBroken = PlayerPrefs.GetInt(name);
}
if(isBroken == 0)
{
oldSprite = 0;
GetComponent<SpriteRenderer>().sprite = sprites[oldSprite];
}
else if (isBroken == 1)
{
oldSprite = 1;
GetComponent<SpriteRenderer>().sprite = sprites[oldSprite];
}
else if (isBroken == 2)
{
oldSprite = 2;
GetComponent<SpriteRenderer>().sprite = sprites[oldSprite];
}
else if(isBroken == 3)
{
gameObject.SetActive(false);
}
@ -32,7 +58,8 @@ public class breakable : MonoBehaviour
IEnumerator Timer()
{
if (timeToBreak == true){
PlayerPrefs.SetInt("rock", 0);
isBroken = 3;
PlayerPrefs.SetInt(name, isBroken);
gameObject.SetActive(false);
}
yield return new WaitForSeconds(1);
@ -52,12 +79,14 @@ public class breakable : MonoBehaviour
newSprite = availableSprites[1];
oldSprite = 1;
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
isBroken = 1;
}
else if (oldSprite == 1)
{
newSprite = availableSprites[2];
oldSprite = 2;
GetComponent<SpriteRenderer>().sprite = sprites[newSprite];
isBroken = 2;
}
else if (oldSprite == 2)
{
@ -69,4 +98,10 @@ public class breakable : MonoBehaviour
}
}
public void SaveCheckpoint()
{
PlayerPrefs.SetInt(name2, isBroken);
}
}

View File

@ -9,32 +9,32 @@ EditorUserSettings:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518c8ea3f7129370bfb25
flags: 0
RecentlyUsedScenePath-1:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a123df6f23b34f1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d051c3de5f5353fe7a923e7ee2e26
flags: 0
RecentlyUsedScenePath-3:
RecentlyUsedScenePath-2:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1827f6e93a3ff1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-4:
RecentlyUsedScenePath-3:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d1a1226ece42776f7e93ffdfe
flags: 0
RecentlyUsedScenePath-5:
RecentlyUsedScenePath-4:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a1532f0e1372ce7f518e8ea3f7129370bfb25
flags: 0
RecentlyUsedScenePath-5:
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a123df6f23b34f1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-6:
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
value: 22424703114646680e0b0227036c72111f19352f223d667d6d0a123df6f23b34f1a923e7ee2e26
flags: 0
RecentlyUsedScenePath-7:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c72111f1958072926337e38271427fb
flags: 0
RecentlyUsedScenePath-9:
RecentlyUsedScenePath-8:
value: 22424703114646680e0b0227036c6c111b07142f1f2b233e2867083debf42d
flags: 0
RecentlyUsedScenePath-9:
value: 22424703114646680e0b0227036c7c1100123d24383a273e2e2c5326ece92021
flags: 0
vcSharedLogLevel:
value: 0d5e400f0650
flags: 0