public virtual void Update() { RaycastHit2D hit = Physics2D.Raycast(transform.position + 0.51f * transform.up, transform.up, 0.01f); if (hit.collider == null) { return; } RayCastDamage damage = hit.collider.GetComponent <RayCastDamage>(); if (damage != null) { if (damage.GetCamp() != GetCamp()) { if (damage.destroyLevel < destroyLevel) { damage.FinishWork(); } } } IAttackable atk = hit.collider.GetComponent <IAttackable>(); if (atk != null) { Debug.Log("In"); if ((atk as ICamp).GetCamp() != GetCamp()) { Damage(atk, damageValue); } } }
/* public virtual void FixedUpdate() * { * RaycastHit2D hit = Physics2D.Raycast(transform.position+transform.up*LineOffset, transform.up, lineLength); * Debug.DrawLine(transform.position + transform.up * LineOffset, transform.position + transform.up * LineOffset + transform.up* lineLength); * if (hit.collider == null) * { * return; * } * RayCastDamage damage = hit.collider.GetComponent<RayCastDamage>(); * if (damage != null) * { * if (damage.GetCamp() != GetCamp()) * { * if (damage.destroyLevel < destroyLevel) * { * damage.FinishWork(); * } * } * } * IAttackable atk = hit.collider.GetComponent<IAttackable>(); * if (atk != null) * { * if ((atk as ICamp).GetCamp() != GetCamp()) * Damage(atk, damageValue); * } * }*/ public void OnTriggerEnter2D(Collider2D collision) { RayCastDamage damage = collision.GetComponent <RayCastDamage>(); if (damage != null) { if (damage.GetCamp() != GetCamp()) { if (damage.destroyLevel < destroyLevel) { damage.FinishWork(); } } } IAttackable atk = collision.GetComponent <IAttackable>(); if (atk != null) { if ((atk as ICamp).GetCamp() != GetCamp()) { Damage(atk, damageValue); } } }