This commit is contained in:
parent
2708deb2b9
commit
ff0ee1a1b6
|
@ -11,10 +11,14 @@ public class PlayerCollideAttack : MonoBehaviour
|
||||||
|
|
||||||
public void OnCollisionEnter2D(Collision2D collision)
|
public void OnCollisionEnter2D(Collision2D collision)
|
||||||
{
|
{
|
||||||
|
if (collision.collider.tag != "Enemy") return;
|
||||||
|
|
||||||
HealthComponent health = collision.collider.gameObject.GetComponent<HealthComponent>();
|
HealthComponent health = collision.collider.gameObject.GetComponent<HealthComponent>();
|
||||||
if (health == null)
|
if (health == null)
|
||||||
health = collision.collider.transform.parent.GetComponent<HealthComponent>();
|
health = collision.collider.transform.parent.GetComponent<HealthComponent>();
|
||||||
if (health == null) return;
|
if (health == null) return;
|
||||||
|
health = collision.collider.gameObject.GetComponentInChildren<HealthComponent>();
|
||||||
|
if (health == null) return;
|
||||||
|
|
||||||
float speed = body.velocity.magnitude;
|
float speed = body.velocity.magnitude;
|
||||||
float damage = speedToDamage.Evaluate(speed);
|
float damage = speedToDamage.Evaluate(speed);
|
||||||
|
|
|
@ -83,11 +83,8 @@ public class PlayerMovement : MonoBehaviour
|
||||||
|
|
||||||
void OnCollisionStay2D(Collision2D collision)
|
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"))
|
if (collision.collider.gameObject.CompareTag("Enemy"))
|
||||||
{ // Other object is an enemy
|
{ // Other object is an enemy
|
||||||
Debug.Log("Hit enememenemy");
|
|
||||||
hp.TakeDamage(1f);
|
hp.TakeDamage(1f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue