Compare commits

..

5 Commits

15 changed files with 635 additions and 68 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
%YAML 1.1 %YAML 1.1
%TAG !u! tag:unity3d.com,2011: %TAG !u! tag:unity3d.com,2011:
--- !u!1 &6232425507328955236 --- !u!1 &6833538753401515138
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
@ -8,10 +8,10 @@ GameObject:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
serializedVersion: 6 serializedVersion: 6
m_Component: m_Component:
- component: {fileID: 81829978540419969} - component: {fileID: 4735696322134991437}
- component: {fileID: 3789424986669542967} - component: {fileID: 2776254023051504893}
- component: {fileID: 3270777934385952829} - component: {fileID: 2851877176569532699}
- component: {fileID: 3979768280741324332} - component: {fileID: 4288064990526774250}
m_Layer: 0 m_Layer: 0
m_Name: DamageText m_Name: DamageText
m_TagString: Untagged m_TagString: Untagged
@ -19,32 +19,32 @@ GameObject:
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 1 m_IsActive: 1
--- !u!224 &81829978540419969 --- !u!224 &4735696322134991437
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6232425507328955236} m_GameObject: {fileID: 6833538753401515138}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_ConstrainProportionsScale: 0 m_ConstrainProportionsScale: 0
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 3288169701052299107}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 0, y: -0.72} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 3, y: 2} m_SizeDelta: {x: 3, y: 2}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0.5, y: 0.5}
--- !u!23 &3789424986669542967 --- !u!23 &2776254023051504893
MeshRenderer: MeshRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6232425507328955236} m_GameObject: {fileID: 6833538753401515138}
m_Enabled: 1 m_Enabled: 1
m_CastShadows: 0 m_CastShadows: 0
m_ReceiveShadows: 0 m_ReceiveShadows: 0
@ -80,13 +80,13 @@ MeshRenderer:
m_SortingLayer: 0 m_SortingLayer: 0
m_SortingOrder: 0 m_SortingOrder: 0
m_AdditionalVertexStreams: {fileID: 0} m_AdditionalVertexStreams: {fileID: 0}
--- !u!114 &3270777934385952829 --- !u!114 &2851877176569532699
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6232425507328955236} m_GameObject: {fileID: 6833538753401515138}
m_Enabled: 1 m_Enabled: 1
m_EditorHideFlags: 0 m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 9541d86e2fd84c1d9990edf0852d74ab, type: 3} m_Script: {fileID: 11500000, guid: 9541d86e2fd84c1d9990edf0852d74ab, type: 3}
@ -109,8 +109,8 @@ MonoBehaviour:
m_fontMaterials: [] m_fontMaterials: []
m_fontColor32: m_fontColor32:
serializedVersion: 2 serializedVersion: 2
rgba: 4279085303 rgba: 4294967295
m_fontColor: {r: 0.9685534, g: 0.6569338, b: 0.051777944, a: 1} m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0 m_enableVertexGradient: 0
m_colorMode: 3 m_colorMode: 3
m_fontColorGradient: m_fontColorGradient:
@ -127,8 +127,8 @@ MonoBehaviour:
m_faceColor: m_faceColor:
serializedVersion: 2 serializedVersion: 2
rgba: 4294967295 rgba: 4294967295
m_fontSize: 5 m_fontSize: 8
m_fontSizeBase: 5 m_fontSizeBase: 8
m_fontWeight: 400 m_fontWeight: 400
m_enableAutoSizing: 0 m_enableAutoSizing: 0
m_fontSizeMin: 18 m_fontSizeMin: 18
@ -170,15 +170,15 @@ MonoBehaviour:
_SortingLayerID: 0 _SortingLayerID: 0
_SortingOrder: 0 _SortingOrder: 0
m_hasFontAssetChanged: 0 m_hasFontAssetChanged: 0
m_renderer: {fileID: 3789424986669542967} m_renderer: {fileID: 2776254023051504893}
m_maskType: 0 m_maskType: 0
--- !u!111 &3979768280741324332 --- !u!111 &4288064990526774250
Animation: Animation:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0} m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 6232425507328955236} m_GameObject: {fileID: 6833538753401515138}
m_Enabled: 1 m_Enabled: 1
serializedVersion: 3 serializedVersion: 3
m_Animation: {fileID: 7400000, guid: a6deca1a46fd10e4c966a1a58f998693, type: 2} m_Animation: {fileID: 7400000, guid: a6deca1a46fd10e4c966a1a58f998693, type: 2}
@ -188,3 +188,78 @@ Animation:
m_PlayAutomatically: 1 m_PlayAutomatically: 1
m_AnimatePhysics: 0 m_AnimatePhysics: 0
m_CullingType: 0 m_CullingType: 0
--- !u!1 &8357464303304312906
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 3288169701052299107}
- component: {fileID: 2241243433806884705}
m_Layer: 0
m_Name: DamageText
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!4 &3288169701052299107
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8357464303304312906}
serializedVersion: 2
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_ConstrainProportionsScale: 0
m_Children:
- {fileID: 4735696322134991437}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &2241243433806884705
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 8357464303304312906}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 01c9b525ae607a844848c8e44062a0f1, type: 3}
m_Name:
m_EditorClassIdentifier:
damageToSize:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 1
value: 1
inSlope: 0.011841985
outSlope: 0.011841985
tangentMode: 0
weightedMode: 0
inWeight: 0
outWeight: 1
- serializedVersion: 3
time: 250
value: 2
inSlope: 0.004031593
outSlope: 0.004031593
tangentMode: 0
weightedMode: 0
inWeight: 0.9989648
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
damageText: {fileID: 2851877176569532699}
normalColor: {r: 0.90943396, g: 0.90943396, b: 0.90943396, a: 1}
critColor: {r: 1, g: 0.63425434, b: 0.2245282, a: 1}
superCritColor: {r: 1, g: 0.103773475, b: 0.103773475, a: 1}
critThreshold: 25
superCritThreshold: 65

View File

@ -1,5 +1,5 @@
fileFormatVersion: 2 fileFormatVersion: 2
guid: 9ac131fe76b864945a3aeb678a16f786 guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3
PrefabImporter: PrefabImporter:
externalObjects: {} externalObjects: {}
userData: userData:

View File

@ -255,6 +255,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
maxHealth: 100 maxHealth: 100
damageTickDelay: 1
OnHealthZero: OnHealthZero:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
@ -276,6 +277,7 @@ MonoBehaviour:
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
maxHealth: 100 maxHealth: 100
damageTickDelay: 0.25
OnHealthZero: OnHealthZero:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []

View File

@ -1702,11 +1702,64 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 880679715} m_GameObject: {fileID: 880679715}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!4 &1053616514 stripped
Transform:
m_CorrespondingSourceObject: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
m_PrefabInstance: {fileID: 1968948229}
m_PrefabAsset: {fileID: 0}
--- !u!4 &1194834060 stripped --- !u!4 &1194834060 stripped
Transform: Transform:
m_CorrespondingSourceObject: {fileID: 320690117028550720, guid: 30e0cc55a67f02d4f92b2677ec4b1511, type: 3} m_CorrespondingSourceObject: {fileID: 320690117028550720, guid: 30e0cc55a67f02d4f92b2677ec4b1511, type: 3}
m_PrefabInstance: {fileID: 869964773} m_PrefabInstance: {fileID: 869964773}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &1206522691
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1206522693}
- component: {fileID: 1206522692}
m_Layer: 0
m_Name: DamageTextManager
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &1206522692
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1206522691}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: aab27275f26e5e244856836f6d17b909, type: 3}
m_Name:
m_EditorClassIdentifier:
textParent: {fileID: 1206522693}
damageTextPrefab: {fileID: 8357464303304312906, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
lifeTime: 3
--- !u!4 &1206522693
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1206522691}
serializedVersion: 2
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_ConstrainProportionsScale: 0
m_Children:
- {fileID: 1053616514}
m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1232208432 --- !u!1001 &1232208432
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3640,6 +3693,66 @@ Transform:
m_Children: [] m_Children: []
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1001 &1968948229
PrefabInstance:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Modification:
serializedVersion: 3
m_TransformParent: {fileID: 1206522693}
m_Modifications:
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalPosition.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalPosition.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalPosition.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalRotation.w
value: 1
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalRotation.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalRotation.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalRotation.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalEulerAnglesHint.x
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalEulerAnglesHint.y
value: 0
objectReference: {fileID: 0}
- target: {fileID: 3288169701052299107, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_LocalEulerAnglesHint.z
value: 0
objectReference: {fileID: 0}
- target: {fileID: 8357464303304312906, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
propertyPath: m_Name
value: DamageText
objectReference: {fileID: 0}
m_RemovedComponents: []
m_RemovedGameObjects: []
m_AddedGameObjects: []
m_AddedComponents:
- targetCorrespondingSourceObject: {fileID: 6833538753401515138, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
insertIndex: -1
addedObject: {fileID: 0}
m_SourcePrefab: {fileID: 100100000, guid: 25c9a2db8fc5b7c4f8feebba5c73e7a3, type: 3}
--- !u!1 &2051970329 --- !u!1 &2051970329
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -4032,3 +4145,4 @@ SceneRoots:
- {fileID: 1920006249} - {fileID: 1920006249}
- {fileID: 640312360} - {fileID: 640312360}
- {fileID: 5796191506433166633} - {fileID: 5796191506433166633}
- {fileID: 1206522693}

View File

@ -78,6 +78,6 @@ Material:
- _UVSec: 0 - _UVSec: 0
- _ZWrite: 1 - _ZWrite: 1
m_Colors: m_Colors:
- _Color: {r: 0.8301887, g: 0.15299344, b: 0.13705944, a: 0.4627451} - _Color: {r: 0.8301887, g: 0.15299338, b: 0.13705936, a: 0.7372549}
- _EmissionColor: {r: 0, g: 0, b: 0, a: 1} - _EmissionColor: {r: 0, g: 0, b: 0, a: 1}
m_BuildTextureStacks: [] m_BuildTextureStacks: []

View File

@ -0,0 +1,15 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DestroyAfter : MonoBehaviour
{
[SerializeField]
private float destroyInSeconds = 1.0f;
public void Init(float delay)
{
this.destroyInSeconds = delay;
Destroy(gameObject, delay);
}
}

View File

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

View File

@ -22,9 +22,9 @@ public class HealthBar : MonoBehaviour
attachedHealth.OnHealthChange.RemoveListener(UpdateHealthBar); attachedHealth.OnHealthChange.RemoveListener(UpdateHealthBar);
} }
private void UpdateHealthBar(int prevHealth, int newHealth) private void UpdateHealthBar(float prevHealth, float newHealth)
{ {
float percent = ((float) newHealth) / ((float)attachedHealth.getMaxHealth()); float percent = newHealth / attachedHealth.getMaxHealth();
healthBarImg.fillAmount = percent; healthBarImg.fillAmount = percent;
} }
} }

View File

@ -1,14 +1,23 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Events; using UnityEngine.Events;
using TMPro; using TMPro;
using System;
using UnityUtils;
public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
{ {
[SerializeField] int maxHealth = 100; [SerializeField] float maxHealth = 100;
public int currentHealth { get; private set; }
[SerializeField] float damageTickDelay = 0.25f;
private float currentDamageTick = 0f;
private float accumulatedDamageInTick = 0f;
public float currentHealth { get; private set; }
public static event Action<Vector3, float> OnHealthChangeAtPos;
public UnityEvent OnHealthZero; public UnityEvent OnHealthZero;
public UnityEvent<int, int> OnHealthChange; public UnityEvent<float, float> OnHealthChange;
[Header("Squeze Damage")] [Header("Squeze Damage")]
[SerializeField] [SerializeField]
@ -22,25 +31,43 @@ public class HealthComponent : MonoBehaviour, ISquezeDamageReceiver
currentHealth = maxHealth; currentHealth = maxHealth;
} }
public int getMaxHealth() { void Update()
{
if (currentDamageTick < Time.time)
{
if (accumulatedDamageInTick < 1f) return;
OnHealthChangeAtPos?.Invoke(transform.position.Add(y: 2f), accumulatedDamageInTick);
currentDamageTick = Time.time + damageTickDelay;
accumulatedDamageInTick = 0f;
}
}
public float getMaxHealth() {
return maxHealth; return maxHealth;
} }
public void setMaxHealth(int amount, bool heal = false) { public void setMaxHealth(float amount, bool heal = false) {
maxHealth = amount; maxHealth = amount;
if (heal) if (heal)
currentHealth = amount; currentHealth = amount;
} }
public void TakeDamage(int damage) public void TakeDamage(float damage)
{ {
currentHealth -= damage; currentHealth -= damage;
OnHealthChange?.Invoke(currentHealth + damage, currentHealth); OnHealthChange?.Invoke(currentHealth + damage, currentHealth);
accumulatedDamageInTick += damage;
if (currentHealth <= 0) { if (currentHealth <= 0) {
// Make sure to flush accumulated when dying
if (accumulatedDamageInTick > 1f)
OnHealthChangeAtPos?.Invoke(transform.position.Add(y: 2f), accumulatedDamageInTick);
OnHealthZero?.Invoke(); OnHealthZero?.Invoke();
BloodComputeShader.Instance.createBlood(transform.position, (int)(maxHealth *maxHealth * BloodComputeShader.Instance.scoreMult), maxHealth / 25.0f); BloodComputeShader.Instance.createBlood(transform.position, (int)(maxHealth *maxHealth * BloodComputeShader.Instance.scoreMult), maxHealth / 8.0f);
} }
} }

View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using TMPro;
public class DamageText : MonoBehaviour
{
[SerializeField] AnimationCurve damageToSize;
[SerializeField] TextMeshPro damageText;
[SerializeField]
private Color normalColor, critColor, superCritColor;
[SerializeField]
private float critThreshold, superCritThreshold;
public void Init(float damage)
{
transform.localScale = Vector3.one * damageToSize.Evaluate(damage);
damageText.color = normalColor;
if (damage > critThreshold)
damageText.color = critColor;
if (damage > superCritThreshold)
damageText.color = superCritColor;
damageText.text = damage.ToString();
}
}

View File

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

View File

@ -0,0 +1,29 @@
using System.Collections;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
public class DamageTextManager : MonoBehaviour
{
[SerializeField] Transform textParent;
[SerializeField] GameObject damageTextPrefab;
[SerializeField] float lifeTime = 3f;
private void OnEnable()
{
HealthComponent.OnHealthChangeAtPos += SpawnDamage;
}
private void OnDisable()
{
HealthComponent.OnHealthChangeAtPos -= SpawnDamage;
}
public void SpawnDamage(Vector3 position, float damage)
{
GameObject go = Instantiate(damageTextPrefab, position, Quaternion.identity, textParent);
go.GetComponent<DamageText>().Init(damage);
go.AddComponent<DestroyAfter>().Init(lifeTime);
}
}

View File

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

View File

@ -24,7 +24,7 @@ public class HealthDisplay : MonoBehaviour
healthComponent.OnHealthChange.RemoveListener(UpdateHealth); healthComponent.OnHealthChange.RemoveListener(UpdateHealth);
} }
public void UpdateHealth(int prevHealth, int newHealth) public void UpdateHealth(float prevHealth, float newHealth)
{ {
healthText.text = padding + healthComponent.currentHealth; healthText.text = padding + healthComponent.currentHealth;
} }