Achievements

This commit is contained in:
Norbi Peti 2020-12-06 21:31:22 +01:00
parent 2b875bebbf
commit 2a31201cec
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
7 changed files with 156 additions and 24 deletions

View file

@ -65,7 +65,7 @@
<Compile Include="Assets\Scripts\Parallaxing.cs" /> <Compile Include="Assets\Scripts\Parallaxing.cs" />
<Compile Include="Assets\Scripts\PlatformSpawner.cs" /> <Compile Include="Assets\Scripts\PlatformSpawner.cs" />
<Compile Include="Assets\Scripts\RocketScript.cs" /> <Compile Include="Assets\Scripts\RocketScript.cs" />
<Compile Include="Assets\Scripts\ScoreSystem.cs" /> <Compile Include="Assets\Scripts\ScoreAndAchievements.cs" />
<Compile Include="Assets\Scripts\Tiling.cs" /> <Compile Include="Assets\Scripts\Tiling.cs" />
<Compile Include="Assets\Scripts\WeaponFireController.cs" /> <Compile Include="Assets\Scripts\WeaponFireController.cs" />
<Reference Include="UnityEngine"> <Reference Include="UnityEngine">

View file

@ -444,6 +444,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
scoreText: {fileID: 211969292} scoreText: {fileID: 211969292}
achievementText: {fileID: 501223422}
--- !u!114 &219260676 --- !u!114 &219260676
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -804,6 +805,84 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
smoothing: 1 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 --- !u!1 &535991315
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -900,6 +979,7 @@ RectTransform:
- {fileID: 984084302} - {fileID: 984084302}
- {fileID: 94608202} - {fileID: 94608202}
- {fileID: 1379112360} - {fileID: 1379112360}
- {fileID: 501223421}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 12 m_RootOrder: 12
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
@ -2387,7 +2467,7 @@ MonoBehaviour:
movementSpeed: 2 movementSpeed: 2
sprintSpeed: 1.5 sprintSpeed: 1.5
platformSpawner: {fileID: 219260673} platformSpawner: {fileID: 219260673}
scoreSystem: {fileID: 219260675} scoreAndAchievements: {fileID: 219260675}
hudManager: {fileID: 219260676} hudManager: {fileID: 219260676}
--- !u!114 &2053847426 --- !u!114 &2053847426
MonoBehaviour: MonoBehaviour:

View file

@ -13,7 +13,7 @@ public class EnemyController : CharacterControllerBase
private short _hitsToRemove; private short _hitsToRemove;
private readonly Random _random = new Random(); private readonly Random _random = new Random();
private PlatformSpawner _platformSpawner; private PlatformSpawner _platformSpawner;
private ScoreSystem _scoreSystem; private ScoreAndAchievements _scoreAndAchievements;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
@ -21,7 +21,7 @@ public class EnemyController : CharacterControllerBase
_rb = GetComponent<Rigidbody2D>(); _rb = GetComponent<Rigidbody2D>();
var gm = GameObject.FindGameObjectWithTag("Game manager"); var gm = GameObject.FindGameObjectWithTag("Game manager");
_platformSpawner = gm.GetComponent<PlatformSpawner>(); _platformSpawner = gm.GetComponent<PlatformSpawner>();
_scoreSystem = gm.GetComponent<ScoreSystem>(); _scoreAndAchievements = gm.GetComponent<ScoreAndAchievements>();
} }
private void OnEnable() private void OnEnable()
@ -64,7 +64,8 @@ public class EnemyController : CharacterControllerBase
_rb.mass = 0.00001f; _rb.mass = 0.00001f;
_rb.gravityScale = 0.01f; _rb.gravityScale = 0.01f;
_rb.freezeRotation = false; _rb.freezeRotation = false;
_scoreSystem.AddScore(1); _scoreAndAchievements.AddScore(1);
_scoreAndAchievements.CountKill();
} }
public bool IsAlive() => _rb.mass > 0.001f; public bool IsAlive() => _rb.mass > 0.001f;

View file

@ -12,7 +12,7 @@ public class OwnCharacterController : CharacterControllerBase
public float movementSpeed; public float movementSpeed;
public float sprintSpeed; public float sprintSpeed;
public PlatformSpawner platformSpawner; public PlatformSpawner platformSpawner;
public ScoreSystem scoreSystem; [FormerlySerializedAs("scoreSystem")] public ScoreAndAchievements scoreAndAchievements;
public HUDManager hudManager; public HUDManager hudManager;
private Vector3 _spawnPos; private Vector3 _spawnPos;
@ -88,7 +88,8 @@ public class OwnCharacterController : CharacterControllerBase
private void CheckpointReached() private void CheckpointReached()
{ {
_spawnPos = _checkpointPos; _spawnPos = _checkpointPos;
scoreSystem.AddScore(100); scoreAndAchievements.AddScore(100);
scoreAndAchievements.NextLevel();
} }
public void Hit() public void Hit()
@ -101,7 +102,7 @@ public class OwnCharacterController : CharacterControllerBase
public void Respawn() public void Respawn()
{ {
scoreSystem.AddScore(-20); scoreAndAchievements.AddScore(-20);
transform.position = _spawnPos; transform.position = _spawnPos;
_health = 100f; _health = 100f;
hudManager.UpdateHealth(_health); hudManager.UpdateHealth(_health);

View file

@ -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);
}
}

View file

@ -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;
}
}