24 lines
727 B
C#
24 lines
727 B
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class PlayerCollideAttack : MonoBehaviour
|
|
{
|
|
[SerializeField] Rigidbody2D body;
|
|
[SerializeField] LayerMask damageLayers;
|
|
|
|
[SerializeField] AnimationCurve speedToDamage;
|
|
|
|
public void OnCollisionEnter2D(Collision2D collision)
|
|
{
|
|
HealthComponent health = collision.collider.gameObject.GetComponent<HealthComponent>();
|
|
if (health == null)
|
|
health = collision.collider.transform.parent.GetComponent<HealthComponent>();
|
|
if (health == null) return;
|
|
|
|
float speed = body.velocity.magnitude;
|
|
float damage = speedToDamage.Evaluate(speed);
|
|
health.TakeDamage(damage);
|
|
}
|
|
}
|