Skip to content

Commit

Permalink
Fixed hit effect player
Browse files Browse the repository at this point in the history
  • Loading branch information
nicorm2000 committed Nov 8, 2023
1 parent b405c50 commit 75bfd56
Show file tree
Hide file tree
Showing 4 changed files with 323 additions and 36 deletions.
257 changes: 256 additions & 1 deletion Assets/Scenes/Level.unity
Original file line number Diff line number Diff line change
Expand Up @@ -3383,6 +3383,81 @@ PrefabInstance:
insertIndex: -1
addedObject: {fileID: 781955555}
m_SourcePrefab: {fileID: 100100000, guid: 10b42574bdd051142bb5f41cd580e099, type: 3}
--- !u!1 &211488839
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 211488840}
- component: {fileID: 211488842}
- component: {fileID: 211488841}
m_Layer: 5
m_Name: Border (3)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &211488840
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 211488839}
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: []
m_Father: {fileID: 833676937}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &211488841
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 211488839}
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: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: ebb6e7afffd865c409285a3513ec0a9c, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &211488842
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 211488839}
m_CullTransparentMesh: 1
--- !u!1001 &211935836
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -11468,6 +11543,81 @@ MonoBehaviour:
positionOffset: {x: 0, y: 0, z: 0}
m_posOffsetData: {fileID: 0}
listenerMask: 1
--- !u!1 &729536248
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 729536249}
- component: {fileID: 729536251}
- component: {fileID: 729536250}
m_Layer: 5
m_Name: Border (1)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &729536249
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 729536248}
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: []
m_Father: {fileID: 833676937}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &729536250
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 729536248}
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: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: ebb6e7afffd865c409285a3513ec0a9c, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &729536251
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 729536248}
m_CullTransparentMesh: 1
--- !u!1 &730331180
GameObject:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -13022,6 +13172,9 @@ RectTransform:
m_ConstrainProportionsScale: 0
m_Children:
- {fileID: 132561237}
- {fileID: 729536249}
- {fileID: 1361837447}
- {fileID: 211488840}
- {fileID: 1662475357}
- {fileID: 1611522410}
- {fileID: 5175508}
Expand Down Expand Up @@ -21215,6 +21368,81 @@ BoxCollider:
serializedVersion: 3
m_Size: {x: 0.0095, y: 0.02, z: 0.0095}
m_Center: {x: 0, y: 0, z: 0}
--- !u!1 &1361837446
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1361837447}
- component: {fileID: 1361837449}
- component: {fileID: 1361837448}
m_Layer: 5
m_Name: Border (2)
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 0
--- !u!224 &1361837447
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1361837446}
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: []
m_Father: {fileID: 833676937}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 1, y: 1}
m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 0, y: 0}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!114 &1361837448
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1361837446}
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: 0, b: 0, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_Sprite: {fileID: 21300000, guid: ebb6e7afffd865c409285a3513ec0a9c, type: 3}
m_Type: 0
m_PreserveAspect: 0
m_FillCenter: 1
m_FillMethod: 4
m_FillAmount: 1
m_FillClockwise: 1
m_FillOrigin: 0
m_UseSpriteMesh: 0
m_PixelsPerUnitMultiplier: 1
--- !u!222 &1361837449
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1361837446}
m_CullTransparentMesh: 1
--- !u!1001 &1368474361
PrefabInstance:
m_ObjectHideFlags: 0
Expand Down Expand Up @@ -30161,7 +30389,34 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: 90c3f290e0aae3e4893d6c9752cc6425, type: 3}
m_Name:
m_EditorClassIdentifier:
border: {fileID: 132561238}
borderCurve:
serializedVersion: 2
m_Curve:
- serializedVersion: 3
time: 0
value: 0
inSlope: 1
outSlope: 1
tangentMode: 34
weightedMode: 0
inWeight: 0
outWeight: 0
- serializedVersion: 3
time: 1
value: 1
inSlope: 1
outSlope: 1
tangentMode: 34
weightedMode: 0
inWeight: 0
outWeight: 0
m_PreInfinity: 2
m_PostInfinity: 2
m_RotationOrder: 4
border1: {fileID: 729536250}
border2: {fileID: 1361837448}
border3: {fileID: 211488841}
borderColorDuration: 1
_maxHealthText: {fileID: 852256658}
_currentHealthText: {fileID: 1247569955}
slider: {fileID: 1089286547}
Expand Down
3 changes: 1 addition & 2 deletions Assets/Scripts/Player/PlayerHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class PlayerHealth : MonoBehaviour

[Header("Player Health UI Dependencies")]
[SerializeField] private PlayerHealthUI playerHealthUI;
[SerializeField] private float borderColorDuration;

[Header("Scene Manager Dependencies")]
[SerializeField] private MySceneManager mySceneManager;
Expand Down Expand Up @@ -52,7 +51,7 @@ private void Update()
public void takeDamage(float damage)
{
StartCoroutine(screenShake.Shake(duration, animationCurve));
StartCoroutine(playerHealthUI.ChangeBorderColor(Color.red, borderColorDuration));
StartCoroutine(playerHealthUI.ChangeBorderColor());

playerData.currentHealth -= damage;
playerHealthUI.SetHealth(playerData.currentHealth);
Expand Down
49 changes: 41 additions & 8 deletions Assets/Scripts/Player/PlayerHealthUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,16 @@

public class PlayerHealthUI : MonoBehaviour
{
[Header("Animation Curve")]
[SerializeField] private AnimationCurve borderCurve;

[Header("Images")]
[SerializeField] private Image border;
[SerializeField] private Image border1;
[SerializeField] private Image border2;
[SerializeField] private Image border3;

[Header("Border Duration")]
[SerializeField] private float borderColorDuration;

[Header("Text Mesh Pro")]
[SerializeField] private TextMeshProUGUI _maxHealthText;
Expand Down Expand Up @@ -71,15 +79,40 @@ public void SetMaxAndCurrentHealth(float maxHealth, float currentHealth)
}

/// <summary>
/// Changes the border color of the UI element for a specified duration.
/// Gradually changes the border color by lowering the alpha value using an animation curve.
/// </summary>
/// <param name="color">The target color for the border.</param>
/// <param name="duration">The duration of the color change.</param>
public IEnumerator ChangeBorderColor(Color color, float duration)
/// <returns>IEnumerator</returns>
public IEnumerator ChangeBorderColor()
{
border.color = color;
yield return new WaitForSeconds(duration);
border1.color = new Color(border1.color.r, border1.color.g, border1.color.b, 1.0f);
border2.color = new Color(border2.color.r, border2.color.g, border2.color.b, 1.0f);
border3.color = new Color(border3.color.r, border3.color.g, border3.color.b, 1.0f);

Color initialColor = border1.color;
float timer = 0f;

border3.gameObject.SetActive(true);
border1.gameObject.SetActive(true);
border2.gameObject.SetActive(true);

while (timer < borderColorDuration)
{
float progress = timer / borderColorDuration;
float alpha = borderCurve.Evaluate(progress);

Color currentColor = initialColor;
currentColor.a = Mathf.Lerp(initialColor.a, 0f, alpha);

border1.color = currentColor;
border2.color = currentColor;
border3.color = currentColor;

yield return null;
timer += Time.deltaTime;
}

border.color = Color.white;
border1.gameObject.SetActive(false);
border2.gameObject.SetActive(false);
border3.gameObject.SetActive(false);
}
}
Loading

0 comments on commit 75bfd56

Please sign in to comment.