Score & HP HUD

This commit is contained in:
Norbi Peti 2020-12-06 18:33:36 +01:00
parent cbabc6e6a2
commit 2b875bebbf
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
16 changed files with 1414 additions and 3 deletions

View file

@ -59,11 +59,13 @@
<Compile Include="Assets\Scripts\CharacterControllerBase.cs" /> <Compile Include="Assets\Scripts\CharacterControllerBase.cs" />
<Compile Include="Assets\Scripts\EnemyController.cs" /> <Compile Include="Assets\Scripts\EnemyController.cs" />
<Compile Include="Assets\Scripts\EnemySpawner.cs" /> <Compile Include="Assets\Scripts\EnemySpawner.cs" />
<Compile Include="Assets\Scripts\HUDManager.cs" />
<Compile Include="Assets\Scripts\ObjectPool.cs" /> <Compile Include="Assets\Scripts\ObjectPool.cs" />
<Compile Include="Assets\Scripts\OwnCharacterController.cs" /> <Compile Include="Assets\Scripts\OwnCharacterController.cs" />
<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\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

@ -0,0 +1,76 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!1 &2830966423841907188
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 4752281081059304708}
- component: {fileID: 440502246605181763}
- component: {fileID: 4716129239565611745}
m_Layer: 5
m_Name: Health1
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &4752281081059304708
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2830966423841907188}
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: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: -255.69, y: 58}
m_SizeDelta: {x: -571.4448, y: -267.6005}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &440502246605181763
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2830966423841907188}
m_CullTransparentMesh: 0
--- !u!114 &4716129239565611745
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 2830966423841907188}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: 4cd54486a573771ffa6ddb648338eabb, type: 3}
m_Type: 3
m_PreserveAspect: 1
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1

View file

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 8992dd160b6b3c0adbad55ef9ea1d06f
PrefabImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because it is too large Load diff

View file

@ -13,12 +13,15 @@ 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;
// Start is called before the first frame update // Start is called before the first frame update
void Start() void Start()
{ {
_rb = GetComponent<Rigidbody2D>(); _rb = GetComponent<Rigidbody2D>();
_platformSpawner = GameObject.FindGameObjectWithTag("Game manager").GetComponent<PlatformSpawner>(); var gm = GameObject.FindGameObjectWithTag("Game manager");
_platformSpawner = gm.GetComponent<PlatformSpawner>();
_scoreSystem = gm.GetComponent<ScoreSystem>();
} }
private void OnEnable() private void OnEnable()
@ -61,6 +64,7 @@ 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);
} }
public bool IsAlive() => _rb.mass > 0.001f; public bool IsAlive() => _rb.mass > 0.001f;

View file

@ -0,0 +1,25 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class HUDManager : MonoBehaviour
{
public Image[] hearts;
public Sprite heartFull, heartHalf, heartEmpty;
public void UpdateHealth(float health)
{
int hpph = 100 / hearts.Length;
for (int i = 0; i < hearts.Length; i++)
{
if (health >= hpph * i + 3 * hpph / 4)
hearts[i].sprite = heartFull;
else if (health < hpph * i + hpph / 4)
hearts[i].sprite = heartEmpty;
else
hearts[i].sprite = heartHalf;
}
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9615a9e1acab3f1818dda2d83d56608c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -3,6 +3,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization;
using Random = System.Random; using Random = System.Random;
public class OwnCharacterController : CharacterControllerBase public class OwnCharacterController : CharacterControllerBase
@ -11,6 +12,8 @@ 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;
public HUDManager hudManager;
private Vector3 _spawnPos; private Vector3 _spawnPos;
private float _health = 100f; private float _health = 100f;
@ -73,7 +76,7 @@ public class OwnCharacterController : CharacterControllerBase
if (_checkpointPos.x > 0 && (tr.position - _checkpointPos).magnitude < 2f) if (_checkpointPos.x > 0 && (tr.position - _checkpointPos).magnitude < 2f)
{ {
_spawnPos = _checkpointPos; CheckpointReached();
_checkpointPosList.RemoveAt(0); _checkpointPosList.RemoveAt(0);
_checkpointPos = _checkpointPosList.Count > 0 ? _checkpointPosList[0] : Vector3.zero; _checkpointPos = _checkpointPosList.Count > 0 ? _checkpointPosList[0] : Vector3.zero;
} }
@ -82,17 +85,26 @@ public class OwnCharacterController : CharacterControllerBase
_animator.SetBool(Sprint, Input.GetButton("Fire3")); _animator.SetBool(Sprint, Input.GetButton("Fire3"));
} }
private void CheckpointReached()
{
_spawnPos = _checkpointPos;
scoreSystem.AddScore(100);
}
public void Hit() public void Hit()
{ {
_health -= (float) _random.NextDouble() % 20f + 20f; _health -= (float) _random.NextDouble() * 20f;
hudManager.UpdateHealth(_health);
if (_health <= 0f) if (_health <= 0f)
Respawn(); Respawn();
} }
public void Respawn() public void Respawn()
{ {
scoreSystem.AddScore(-20);
transform.position = _spawnPos; transform.position = _spawnPos;
_health = 100f; _health = 100f;
hudManager.UpdateHealth(_health);
_rb.velocity = Vector2.zero; _rb.velocity = Vector2.zero;
} }

View file

@ -0,0 +1,16 @@
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;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 82c5ad49699c22f4fb38fb14d1d0115c
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,92 @@
fileFormatVersion: 2
guid: 06180f88b551009999a4d2dd3bb23b46
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View file

@ -0,0 +1,92 @@
fileFormatVersion: 2
guid: 4cd54486a573771ffa6ddb648338eabb
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

@ -0,0 +1,92 @@
fileFormatVersion: 2
guid: 4f34e41f0677bc9b894c9611e42311ed
TextureImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 11
mipmaps:
mipMapMode: 0
enableMipMap: 0
sRGBTexture: 1
linearTexture: 0
fadeOut: 0
borderMipMap: 0
mipMapsPreserveCoverage: 0
alphaTestReferenceValue: 0.5
mipMapFadeDistanceStart: 1
mipMapFadeDistanceEnd: 3
bumpmap:
convertToNormalMap: 0
externalNormalMap: 0
heightScale: 0.25
normalMapFilter: 0
isReadable: 0
streamingMipmaps: 0
streamingMipmapsPriority: 0
grayScaleToAlpha: 0
generateCubemap: 6
cubemapConvolution: 0
seamlessCubemap: 0
textureFormat: 1
maxTextureSize: 2048
textureSettings:
serializedVersion: 2
filterMode: -1
aniso: -1
mipBias: -100
wrapU: 1
wrapV: 1
wrapW: 1
nPOTScale: 0
lightmap: 0
compressionQuality: 50
spriteMode: 1
spriteExtrude: 1
spriteMeshType: 1
alignment: 0
spritePivot: {x: 0.5, y: 0.5}
spritePixelsToUnits: 100
spriteBorder: {x: 0, y: 0, z: 0, w: 0}
spriteGenerateFallbackPhysicsShape: 1
alphaUsage: 1
alphaIsTransparency: 1
spriteTessellationDetail: -1
textureType: 8
textureShape: 1
singleChannelComponent: 0
maxTextureSizeSet: 0
compressionQualitySet: 0
textureFormatSet: 0
applyGammaDecoding: 0
platformSettings:
- serializedVersion: 3
buildTarget: DefaultTexturePlatform
maxTextureSize: 2048
resizeAlgorithm: 0
textureFormat: -1
textureCompression: 1
compressionQuality: 50
crunchedCompression: 0
allowsAlphaSplitting: 0
overridden: 0
androidETC2FallbackOverride: 0
forceMaximumCompressionQuality_BC6H_BC7: 0
spriteSheet:
serializedVersion: 2
sprites: []
outline: []
physicsShape: []
bones: []
spriteID: 5e97eb03825dee720800000000000000
internalID: 0
vertices: []
indices:
edges: []
weights: []
secondaryTextures: []
spritePackingTag:
pSDRemoveMatte: 0
pSDShowRemoveMatteOption: 0
userData:
assetBundleName:
assetBundleVariant: