2025-01-17 19:46:17 -05:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
[RequireComponent(typeof(Rigidbody2D))]
|
|
|
|
|
[RequireComponent(typeof(Collider2D))]
|
|
|
|
|
[RequireComponent(typeof(RespawnOnTriggerEnter))]
|
|
|
|
|
public class Damageable : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public float force = 50f;
|
|
|
|
|
public float damage = 0f;
|
|
|
|
|
|
|
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
|
{
|
|
|
|
|
if (collision.gameObject.CompareTag("Punch Hurtbox"))
|
|
|
|
|
{
|
2025-01-31 12:48:13 -05:00
|
|
|
if (GetComponent<Block>().blocking)
|
|
|
|
|
{
|
|
|
|
|
collision.gameObject.GetComponent<Damageable>().Damage(gameObject);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
Damage(collision.transform.parent.gameObject);
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Recoil(GameObject damageSource)
|
|
|
|
|
{
|
|
|
|
|
GetComponent<Rigidbody2D>().AddForce(((transform.position - damageSource.transform.position).normalized + Vector3.up) * damage, ForceMode2D.Force);
|
2025-01-17 20:11:04 -05:00
|
|
|
//damageSource.transform.localScale *= 1.1f;
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
|
2025-01-31 12:48:13 -05:00
|
|
|
public void Damage(GameObject source)
|
2025-01-17 19:46:17 -05:00
|
|
|
{
|
|
|
|
|
damage += force;
|
2025-01-31 12:48:13 -05:00
|
|
|
Recoil(source);
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void ResetDamage()
|
|
|
|
|
{
|
|
|
|
|
damage = 0f;
|
2025-01-17 20:11:04 -05:00
|
|
|
//transform.localScale = Vector3.one;
|
2025-01-17 19:46:17 -05:00
|
|
|
}
|
|
|
|
|
}
|