Skip to content

Commit

Permalink
Player HealthBar Visual
Browse files Browse the repository at this point in the history
  • Loading branch information
LordEvil1 committed Mar 23, 2024
1 parent c71cc02 commit ed4fd63
Show file tree
Hide file tree
Showing 8 changed files with 331 additions and 415 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,6 @@ public override void OnDieHandler(){

public void UpdateHealthStat(){
playerStats.health = GetCurrentHealth();
playerStats.maxHealth = GetMaxHealthCount();
}
}
10 changes: 10 additions & 0 deletions Assets/Code/Scripts/Characters/Player/Stats/playerStats.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ public static float health{
return _health;
}
}
private static float _maxHealth;
public static float maxHealth{
set{
_maxHealth = value;
OnStatsChange();
}
get{
return _maxHealth;
}
}
private static float _fireRate;
public static float fireRate{
set{
Expand Down
3 changes: 3 additions & 0 deletions Assets/Code/Scripts/Features/HealthSystem/IHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public virtual void Heal(float healthCount){
public float GetCurrentHealth(){
return CurrentHealth;
}
public float GetMaxHealthCount(){
return MaxHealth;
}
public abstract void OnHealHandler();
public abstract void OnDamageHandler();
public abstract void OnDieHandler();
Expand Down
21 changes: 20 additions & 1 deletion Assets/Code/Scripts/UI/Characters/Player/Stats/PlayerStatsUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ public class PlayerStatsUI : MonoBehaviour
{

public Text healthText;
public Image healthBar;
public Text fireRateText;
public Text RangeText;
//public Text moveSpeedText;
Expand All @@ -24,15 +25,33 @@ private void Awake()
//case "moveSpeedText" : moveSpeedText = text; break;
}
}
Image[] imagesBars = GetComponentsInChildren<Image>();
foreach (var bar in imagesBars)
{
switch (bar.gameObject.name)
{
case "healthBar" : healthBar = bar; break;
//case "fireRateBar" : fireRateBar = bar; break;
//case "RangeBar" : RangeBar = bar; break;
//case "moveSpeedImage" : moveSpeedImage = Image; break;
}
}
UpdateUI();
}

public void UpdateUI()
{
healthText.text = playerStats.health.ToString();
UpdateHealthUI();
fireRateText.text = playerStats.fireRate.ToString();
RangeText.text = playerStats.range.ToString();
//moveSpeedText.text = playerStats.moveSpeed.ToString();
// Update other UI components as needed
}

public void UpdateHealthUI(){
var health = playerStats.health;
var maxHealth = playerStats.maxHealth;
healthText.text = health.ToString();
healthBar.fillAmount = Mathf.Clamp01(health / maxHealth);
}
}
181 changes: 99 additions & 82 deletions Assets/Resources/Level/Prefabs/Boosts/Healing Boost.prefab
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ GameObject:
- component: {fileID: 1490971374108023528}
- component: {fileID: 1490971374108023529}
- component: {fileID: 1490971374108023526}
- component: {fileID: 997308605}
m_Layer: 0
m_Name: Healing Boost
m_TagString: Untagged
Expand All @@ -27,10 +28,10 @@ Transform:
m_GameObject: {fileID: 1490971374108023530}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: -21.4, y: 2.12, z: 0}
m_LocalScale: {x: 4.5002, y: 4.5002, z: 4.5002}
m_ConstrainProportionsScale: 0
m_LocalScale: {x: 6, y: 6, z: 6}
m_ConstrainProportionsScale: 1
m_Children:
- {fileID: 1490971374199485896}
- {fileID: 2086373578564376170}
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
Expand Down Expand Up @@ -60,88 +61,104 @@ BoxCollider:
m_IsTrigger: 0
m_Enabled: 1
serializedVersion: 2
m_Size: {x: 0.5, y: 0.5, z: 0.5}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1490971374199485899
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1490971374199485896}
- component: {fileID: 1490971374199485895}
- component: {fileID: 1490971374199485894}
m_Layer: 0
m_Name: Sphere
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &1490971374199485896
Transform:
m_Size: {x: 0.5, y: 0.81376344, z: 0.5}
m_Center: {x: 0, y: 0.15688153, z: 0}
--- !u!95 &997308605
Animator:
serializedVersion: 5
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1490971374199485899}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 0.41664, y: 0.41664, z: 0.41664}
m_ConstrainProportionsScale: 0
m_Children: []
m_Father: {fileID: 1490971374108023528}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!33 &1490971374199485895
MeshFilter:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1490971374199485899}
m_Mesh: {fileID: 10207, guid: 0000000000000000e000000000000000, type: 0}
--- !u!23 &1490971374199485894
MeshRenderer:
m_GameObject: {fileID: 1490971374108023530}
m_Enabled: 1
m_Avatar: {fileID: 0}
m_Controller: {fileID: 9100000, guid: ebd6817fe2bacb24fa6a869a1a7b5324, type: 2}
m_CullingMode: 0
m_UpdateMode: 0
m_ApplyRootMotion: 0
m_LinearVelocityBlending: 0
m_StabilizeFeet: 0
m_WarningMessage:
m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorStateOnDisable: 0
m_WriteDefaultValuesOnDisable: 0
--- !u!1001 &1981285637766672769
PrefabInstance:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
serializedVersion: 2
m_Modification:
m_TransformParent: {fileID: 1490971374108023528}
m_Modifications:
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_RootOrder
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalScale.x
value: 10
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalScale.y
value: 10
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalScale.z
value: 10
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalPosition.x
value: -0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalPosition.y
value: 0.3
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalRotation.w
value: 0.9063079
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalRotation.x
value: -0.42261827
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: -50
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_ConstrainProportionsScale
value: 1
objectReference: {fileID: 0}
- target: {fileID: 919132149155446097, guid: 36d0005da455ec846a713247495b9760, type: 3}
propertyPath: m_Name
value: heart
objectReference: {fileID: 0}
m_RemovedComponents: []
m_SourcePrefab: {fileID: 100100000, guid: 36d0005da455ec846a713247495b9760, type: 3}
--- !u!4 &2086373578564376170 stripped
Transform:
m_CorrespondingSourceObject: {fileID: -8679921383154817045, guid: 36d0005da455ec846a713247495b9760, type: 3}
m_PrefabInstance: {fileID: 1981285637766672769}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1490971374199485899}
m_Enabled: 1
m_CastShadows: 1
m_ReceiveShadows: 1
m_DynamicOccludee: 1
m_StaticShadowCaster: 0
m_MotionVectors: 1
m_LightProbeUsage: 1
m_ReflectionProbeUsage: 1
m_RayTracingMode: 2
m_RayTraceProcedural: 0
m_RenderingLayerMask: 1
m_RendererPriority: 0
m_Materials:
- {fileID: 10303, guid: 0000000000000000f000000000000000, type: 0}
m_StaticBatchInfo:
firstSubMesh: 0
subMeshCount: 0
m_StaticBatchRoot: {fileID: 0}
m_ProbeAnchor: {fileID: 0}
m_LightProbeVolumeOverride: {fileID: 0}
m_ScaleInLightmap: 1
m_ReceiveGI: 1
m_PreserveUVs: 0
m_IgnoreNormalsForChartDetection: 0
m_ImportantGI: 0
m_StitchLightmapSeams: 1
m_SelectedEditorRenderState: 3
m_MinimumChartSize: 4
m_AutoUVMaxDistance: 0.5
m_AutoUVMaxAngle: 89
m_LightmapParameters: {fileID: 0}
m_SortingLayerID: 0
m_SortingLayer: 0
m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0}
Loading

0 comments on commit ed4fd63

Please sign in to comment.