diff --git a/Assembly-CSharp.csproj b/Assembly-CSharp.csproj
index 8fe04bb..5af5081 100644
--- a/Assembly-CSharp.csproj
+++ b/Assembly-CSharp.csproj
@@ -65,7 +65,7 @@
-
+
diff --git a/Assets/Scenes/Main.unity b/Assets/Scenes/Main.unity
index c4e560c..f9c7b3e 100644
--- a/Assets/Scenes/Main.unity
+++ b/Assets/Scenes/Main.unity
@@ -444,6 +444,7 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
scoreText: {fileID: 211969292}
+ achievementText: {fileID: 501223422}
--- !u!114 &219260676
MonoBehaviour:
m_ObjectHideFlags: 0
@@ -804,6 +805,84 @@ MonoBehaviour:
m_Name:
m_EditorClassIdentifier:
smoothing: 1
+--- !u!1 &501223420
+GameObject:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ serializedVersion: 6
+ m_Component:
+ - component: {fileID: 501223421}
+ - component: {fileID: 501223423}
+ - component: {fileID: 501223422}
+ m_Layer: 5
+ m_Name: AchievementText
+ m_TagString: Untagged
+ m_Icon: {fileID: 0}
+ m_NavMeshLayer: 0
+ m_StaticEditorFlags: 0
+ m_IsActive: 1
+--- !u!224 &501223421
+RectTransform:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 501223420}
+ 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: 535991319}
+ m_RootOrder: 6
+ m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
+ m_AnchorMin: {x: 0, y: 1}
+ m_AnchorMax: {x: 1, y: 1}
+ m_AnchoredPosition: {x: -9.5, y: -42.6}
+ m_SizeDelta: {x: -445, y: 30}
+ m_Pivot: {x: 0.5, y: 0.5}
+--- !u!114 &501223422
+MonoBehaviour:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 501223420}
+ 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: 1, g: 0.4, b: 0, a: 1}
+ m_RaycastTarget: 1
+ m_Maskable: 1
+ m_OnCullStateChanged:
+ m_PersistentCalls:
+ m_Calls: []
+ m_FontData:
+ m_Font: {fileID: 10102, guid: 0000000000000000e000000000000000, type: 0}
+ m_FontSize: 20
+ m_FontStyle: 0
+ m_BestFit: 0
+ m_MinSize: 2
+ m_MaxSize: 40
+ m_Alignment: 4
+ m_AlignByGeometry: 0
+ m_RichText: 1
+ m_HorizontalOverflow: 1
+ m_VerticalOverflow: 1
+ m_LineSpacing: 1
+ m_Text: Achievement
+--- !u!222 &501223423
+CanvasRenderer:
+ m_ObjectHideFlags: 0
+ m_CorrespondingSourceObject: {fileID: 0}
+ m_PrefabInstance: {fileID: 0}
+ m_PrefabAsset: {fileID: 0}
+ m_GameObject: {fileID: 501223420}
+ m_CullTransparentMesh: 0
--- !u!1 &535991315
GameObject:
m_ObjectHideFlags: 0
@@ -900,6 +979,7 @@ RectTransform:
- {fileID: 984084302}
- {fileID: 94608202}
- {fileID: 1379112360}
+ - {fileID: 501223421}
m_Father: {fileID: 0}
m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@@ -2387,7 +2467,7 @@ MonoBehaviour:
movementSpeed: 2
sprintSpeed: 1.5
platformSpawner: {fileID: 219260673}
- scoreSystem: {fileID: 219260675}
+ scoreAndAchievements: {fileID: 219260675}
hudManager: {fileID: 219260676}
--- !u!114 &2053847426
MonoBehaviour:
diff --git a/Assets/Scripts/EnemyController.cs b/Assets/Scripts/EnemyController.cs
index 61efb83..e0c6de0 100644
--- a/Assets/Scripts/EnemyController.cs
+++ b/Assets/Scripts/EnemyController.cs
@@ -13,7 +13,7 @@ public class EnemyController : CharacterControllerBase
private short _hitsToRemove;
private readonly Random _random = new Random();
private PlatformSpawner _platformSpawner;
- private ScoreSystem _scoreSystem;
+ private ScoreAndAchievements _scoreAndAchievements;
// Start is called before the first frame update
void Start()
@@ -21,7 +21,7 @@ public class EnemyController : CharacterControllerBase
_rb = GetComponent();
var gm = GameObject.FindGameObjectWithTag("Game manager");
_platformSpawner = gm.GetComponent();
- _scoreSystem = gm.GetComponent();
+ _scoreAndAchievements = gm.GetComponent();
}
private void OnEnable()
@@ -64,7 +64,8 @@ public class EnemyController : CharacterControllerBase
_rb.mass = 0.00001f;
_rb.gravityScale = 0.01f;
_rb.freezeRotation = false;
- _scoreSystem.AddScore(1);
+ _scoreAndAchievements.AddScore(1);
+ _scoreAndAchievements.CountKill();
}
public bool IsAlive() => _rb.mass > 0.001f;
diff --git a/Assets/Scripts/OwnCharacterController.cs b/Assets/Scripts/OwnCharacterController.cs
index aaa4db2..de990bf 100644
--- a/Assets/Scripts/OwnCharacterController.cs
+++ b/Assets/Scripts/OwnCharacterController.cs
@@ -12,7 +12,7 @@ public class OwnCharacterController : CharacterControllerBase
public float movementSpeed;
public float sprintSpeed;
public PlatformSpawner platformSpawner;
- public ScoreSystem scoreSystem;
+ [FormerlySerializedAs("scoreSystem")] public ScoreAndAchievements scoreAndAchievements;
public HUDManager hudManager;
private Vector3 _spawnPos;
@@ -88,7 +88,8 @@ public class OwnCharacterController : CharacterControllerBase
private void CheckpointReached()
{
_spawnPos = _checkpointPos;
- scoreSystem.AddScore(100);
+ scoreAndAchievements.AddScore(100);
+ scoreAndAchievements.NextLevel();
}
public void Hit()
@@ -101,7 +102,7 @@ public class OwnCharacterController : CharacterControllerBase
public void Respawn()
{
- scoreSystem.AddScore(-20);
+ scoreAndAchievements.AddScore(-20);
transform.position = _spawnPos;
_health = 100f;
hudManager.UpdateHealth(_health);
diff --git a/Assets/Scripts/ScoreAndAchievements.cs b/Assets/Scripts/ScoreAndAchievements.cs
new file mode 100644
index 0000000..4b41071
--- /dev/null
+++ b/Assets/Scripts/ScoreAndAchievements.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine;
+using UnityEngine.UI;
+
+public class ScoreAndAchievements : MonoBehaviour
+{
+ public Text scoreText;
+ public Text achievementText;
+ private int _score;
+ private float _displayedTime;
+ private int _killCount;
+ private int _level;
+
+ private void Start()
+ {
+ achievementText.text = "";
+ }
+
+ private void Update()
+ {
+ if (_displayedTime > 0 && Time.time - _displayedTime > 5f)
+ {
+ achievementText.text = "";
+ _displayedTime = 0;
+ }
+ }
+
+ public void AddScore(int score)
+ {
+ _score += score;
+ scoreText.text = "Score: " + _score;
+ }
+
+ public void CountKill()
+ {
+ _killCount++;
+
+ if (_killCount == 1)
+ CheckAndDisplayAchievement("Kills", 1, "First kill");
+ else if (_killCount == 25)
+ CheckAndDisplayAchievement("Kills", 2, "25 kills");
+ else if (_killCount == 50)
+ CheckAndDisplayAchievement("Kills", 3, "50 kills");
+ }
+
+ public void NextLevel()
+ {
+ _level++;
+ if (_level == 5)
+ CheckAndDisplayAchievement("NextLevel", 1, "Level 5 completed");
+ else if (_level == 8)
+ CheckAndDisplayAchievement("NextLevel", 2, "Level 8 completed");
+ else if (_level == 10)
+ CheckAndDisplayAchievement("NextLevel", 3, "This is so next level");
+ }
+
+ private void CheckAndDisplayAchievement(string key, int value, string message)
+ {
+ if (PlayerPrefs.GetInt(key) >= value) return;
+ achievementText.text = message;
+ _displayedTime = Time.time;
+ PlayerPrefs.SetInt(key, value);
+ }
+}
\ No newline at end of file
diff --git a/Assets/Scripts/ScoreSystem.cs.meta b/Assets/Scripts/ScoreAndAchievements.cs.meta
similarity index 100%
rename from Assets/Scripts/ScoreSystem.cs.meta
rename to Assets/Scripts/ScoreAndAchievements.cs.meta
diff --git a/Assets/Scripts/ScoreSystem.cs b/Assets/Scripts/ScoreSystem.cs
deleted file mode 100644
index be0af4d..0000000
--- a/Assets/Scripts/ScoreSystem.cs
+++ /dev/null
@@ -1,16 +0,0 @@
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEngine.UI;
-
-public class ScoreSystem : MonoBehaviour
-{
- public Text scoreText;
- private int _score;
-
- public void AddScore(int score)
- {
- _score += score;
- scoreText.text = "Score: " + _score;
- }
-}