Merge branch 'damage-handling'
This commit is contained in:
@@ -488,9 +488,11 @@ MonoBehaviour:
|
|||||||
m_Script: {fileID: 11500000, guid: 2b3b9fc97a2d39d2d84c4be43a79247a, type: 3}
|
m_Script: {fileID: 11500000, guid: 2b3b9fc97a2d39d2d84c4be43a79247a, type: 3}
|
||||||
m_Name:
|
m_Name:
|
||||||
m_EditorClassIdentifier: Assembly-CSharp::DamageHandler
|
m_EditorClassIdentifier: Assembly-CSharp::DamageHandler
|
||||||
threshold: 0
|
threshold: 2.5
|
||||||
multiplier: 5
|
multiplier: 0.5
|
||||||
health: 1
|
maxHealth: 1
|
||||||
|
health: 0
|
||||||
|
minSize: 0.4
|
||||||
--- !u!1001 &1445156949
|
--- !u!1001 &1445156949
|
||||||
PrefabInstance:
|
PrefabInstance:
|
||||||
m_ObjectHideFlags: 0
|
m_ObjectHideFlags: 0
|
||||||
@@ -773,7 +775,7 @@ PrefabInstance:
|
|||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3}
|
- target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3}
|
||||||
propertyPath: m_LocalPosition.y
|
propertyPath: m_LocalPosition.y
|
||||||
value: -4.84
|
value: -20.5
|
||||||
objectReference: {fileID: 0}
|
objectReference: {fileID: 0}
|
||||||
- target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3}
|
- target: {fileID: 2163867978973577705, guid: 2f44dc6d6adb9ae7f9b4f644da0e3485, type: 3}
|
||||||
propertyPath: m_LocalPosition.z
|
propertyPath: m_LocalPosition.z
|
||||||
|
|||||||
@@ -1,12 +1,21 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using Object = System.Object;
|
||||||
|
|
||||||
public class DamageHandler : MonoBehaviour
|
public class DamageHandler : MonoBehaviour
|
||||||
{
|
{
|
||||||
public float threshold = 0.05f;
|
public float threshold = 0.05f;
|
||||||
public float multiplier = 5f;
|
public float multiplier = 5f;
|
||||||
|
|
||||||
public float health = 1;
|
public float maxHealth = 1f;
|
||||||
|
public float health;
|
||||||
|
public float minSize = 0.4f;
|
||||||
|
|
||||||
|
|
||||||
|
private void Start()
|
||||||
|
{
|
||||||
|
health = maxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
private void OnCollisionEnter2D(Collision2D other)
|
private void OnCollisionEnter2D(Collision2D other)
|
||||||
{
|
{
|
||||||
@@ -15,11 +24,32 @@ public class DamageHandler : MonoBehaviour
|
|||||||
{
|
{
|
||||||
float fallDamage = (fallSpeed - threshold) * multiplier;
|
float fallDamage = (fallSpeed - threshold) * multiplier;
|
||||||
Debug.Log($"Fell with velocity:{fallSpeed}. Fall damage{fallDamage}");
|
Debug.Log($"Fell with velocity:{fallSpeed}. Fall damage{fallDamage}");
|
||||||
health -= fallDamage;
|
UpdateHealth(health - fallDamage);
|
||||||
|
// Debug.Log($"New health:{health - fallDamage}");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Debug.Log($"Fell with velocity:{fallSpeed}. No fall damage");
|
Debug.Log($"Fell with velocity:{fallSpeed}. No fall damage");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void UpdateHealth(float health)
|
||||||
|
{
|
||||||
|
this.health = health;
|
||||||
|
Transform transform = GetComponent<Transform>();
|
||||||
|
float healthScaling = minSize + (1 - minSize) * (this.health / maxHealth);
|
||||||
|
transform.localScale = new Vector3(healthScaling,healthScaling,healthScaling);
|
||||||
|
Debug.Log("UpdatedScale and health");
|
||||||
|
|
||||||
|
if(this.health <= 0f)
|
||||||
|
{
|
||||||
|
Debug.Log("Die");
|
||||||
|
Die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Die()
|
||||||
|
{
|
||||||
|
Destroy(gameObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user