From ff0ee1a1b6e22607fa97b15d16ef5aa356ef6679 Mon Sep 17 00:00:00 2001 From: Sveske Juice Date: Sun, 4 Feb 2024 00:24:51 -0800 Subject: [PATCH] L --- Assets/Scripts/Player/PlayerCollideAttack.cs | 4 ++++ Assets/Scripts/Player/PlayerMovement.cs | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Assets/Scripts/Player/PlayerCollideAttack.cs b/Assets/Scripts/Player/PlayerCollideAttack.cs index d41ef29..458f924 100644 --- a/Assets/Scripts/Player/PlayerCollideAttack.cs +++ b/Assets/Scripts/Player/PlayerCollideAttack.cs @@ -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(); if (health == null) health = collision.collider.transform.parent.GetComponent(); if (health == null) return; + health = collision.collider.gameObject.GetComponentInChildren(); + if (health == null) return; float speed = body.velocity.magnitude; float damage = speedToDamage.Evaluate(speed); diff --git a/Assets/Scripts/Player/PlayerMovement.cs b/Assets/Scripts/Player/PlayerMovement.cs index 22d08b1..ea59093 100644 --- a/Assets/Scripts/Player/PlayerMovement.cs +++ b/Assets/Scripts/Player/PlayerMovement.cs @@ -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); } }