This commit is contained in:
Sveske Juice 2024-02-04 00:24:51 -08:00
parent 2708deb2b9
commit ff0ee1a1b6
2 changed files with 4 additions and 3 deletions

View File

@ -11,10 +11,14 @@ public class PlayerCollideAttack : MonoBehaviour
public void OnCollisionEnter2D(Collision2D collision)
{
if (collision.collider.tag != "Enemy") return;
HealthComponent health = collision.collider.gameObject.GetComponent<HealthComponent>();
if (health == null)
health = collision.collider.transform.parent.GetComponent<HealthComponent>();
if (health == null) return;
health = collision.collider.gameObject.GetComponentInChildren<HealthComponent>();
if (health == null) return;
float speed = body.velocity.magnitude;
float damage = speedToDamage.Evaluate(speed);

View File

@ -83,11 +83,8 @@ public class PlayerMovement : MonoBehaviour
void OnCollisionStay2D(Collision2D collision)
{
Debug.Log("Hit other " + collision.otherCollider.gameObject.name);
Debug.Log("Hit other " + collision.collider.gameObject.name);
if (collision.collider.gameObject.CompareTag("Enemy"))
{ // Other object is an enemy
Debug.Log("Hit enememenemy");
hp.TakeDamage(1f);
}
}