Skip to content

Commit

Permalink
Update score saving system
Browse files Browse the repository at this point in the history
  • Loading branch information
JadenBalogh committed Jun 29, 2020
1 parent 5049815 commit ed890a2
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 29 deletions.
8 changes: 0 additions & 8 deletions Assets/Resources.meta

This file was deleted.

1 change: 0 additions & 1 deletion Assets/Resources/Best.txt

This file was deleted.

7 changes: 0 additions & 7 deletions Assets/Resources/Best.txt.meta

This file was deleted.

95 changes: 95 additions & 0 deletions Assets/Scenes/Main.unity
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,7 @@ RectTransform:
m_Children:
- {fileID: 1370914465}
- {fileID: 1827328624}
- {fileID: 1960128030}
m_Father: {fileID: 1222208828}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -2234,3 +2235,97 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1929354427}
m_CullTransparentMesh: 0
--- !u!1 &1960128029
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1960128030}
- component: {fileID: 1960128033}
- component: {fileID: 1960128032}
- component: {fileID: 1960128031}
m_Layer: 5
m_Name: CreditsText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1960128030
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1960128029}
m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 612192587}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 0}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 40}
m_Pivot: {x: 0.5, y: 0}
--- !u!114 &1960128031
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1960128029}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: e19747de3f5aca642ab2be37e372fb86, type: 3}
m_Name:
m_EditorClassIdentifier:
m_EffectColor: {r: 0, g: 0, b: 0, a: 1}
m_EffectDistance: {x: 2, y: -2}
m_UseGraphicAlpha: 1
--- !u!114 &1960128032
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1960128029}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 5f7201a12d95ffc409449d95f23cf332, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 0.8901961, g: 0.8901961, b: 0.8901961, a: 1}
m_RaycastTarget: 0
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_FontData:
m_Font: {fileID: 12800000, guid: 45baa9c345360b14fba3a7651c760fff, type: 3}
m_FontSize: 28
m_FontStyle: 0
m_BestFit: 0
m_MinSize: 0
m_MaxSize: 84
m_Alignment: 4
m_AlignByGeometry: 1
m_RichText: 1
m_HorizontalOverflow: 1
m_VerticalOverflow: 1
m_LineSpacing: 1
m_Text: Created by Jaden Balogh and Adam Collins
--- !u!222 &1960128033
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1960128029}
m_CullTransparentMesh: 0
20 changes: 7 additions & 13 deletions Assets/Scripts/GameController.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.SceneManagement;

Expand All @@ -26,8 +25,6 @@ public class GameController : MonoBehaviour
private int score;
private int bestScore;

private const string savePath = "Assets/Resources/Best.txt";

void Awake() {
if (instance != null) {
Destroy(gameObject);
Expand Down Expand Up @@ -119,18 +116,15 @@ private void SpawnPipe() {
}

private void SaveBestScore() {
StreamWriter writer = new StreamWriter(savePath);
writer.Write(score);
writer.Close();
PlayerPrefs.SetInt("BestScore", bestScore);
PlayerPrefs.Save();
}

private int LoadBestScore() {
StreamReader reader = new StreamReader(savePath);
int best;
if (!System.Int32.TryParse(reader.ReadLine(), out best)) {
best = 0;
}
reader.Close();
return best;
return PlayerPrefs.GetInt("BestScore", 0);
}

private void ClearBestScore() {
PlayerPrefs.DeleteAll();
}
}

0 comments on commit ed890a2

Please sign in to comment.