public static HitBarPoints GetBoundPoint(this BoxCollider boxCollider, Transform torso, LayerMask mask) { HitBarPoints bp = new HitBarPoints(); var boxPoint = boxCollider.GetBoxPoint(); Ray toTop = new Ray(boxPoint.top, boxPoint.top - torso.position); Ray toCenter = new Ray(torso.position, boxPoint.center - torso.position); Ray toBottom = new Ray(torso.position, boxPoint.bottom - torso.position); Debug.DrawRay(toTop.origin, toTop.direction, Color.red, 2); Debug.DrawRay(toCenter.origin, toCenter.direction, Color.green, 2); Debug.DrawRay(toBottom.origin, toBottom.direction, Color.blue, 2); RaycastHit hit; var dist = Vector3.Distance(torso.position, boxPoint.top); if (Physics.Raycast(toTop, out hit, dist, mask)) { bp |= HitBarPoints.Top; Debug.Log(hit.transform.name); } dist = Vector3.Distance(torso.position, boxPoint.center); if (Physics.Raycast(toCenter, out hit, dist, mask)) { bp |= HitBarPoints.Center; Debug.Log(hit.transform.name); } dist = Vector3.Distance(torso.position, boxPoint.bottom); if (Physics.Raycast(toBottom, out hit, dist, mask)) { bp |= HitBarPoints.Bottom; Debug.Log(hit.transform.name); } return(bp); }
void TryApplyDamage(Collider other, Damage damage, HitBarPoints hitBarPoint) { damage.sender = transform; damage.recoil_id = currentRecoilLevel; switch (hitBarPoint) { case HitBarPoints.Top: if (!hitTopColliders.Contains(other)) { other.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver); hitTopColliders.Add(other); } break; case HitBarPoints.Center: if (!hitCenterColliders.Contains(other)) { other.SendMessage("TakeDamage", damage, SendMessageOptions.DontRequireReceiver); hitCenterColliders.Add(other); } break; } }
public HitInfo(Collider hitCollider, Vector3 hitPoint, HitBarPoints hitBarPoint) { this.hitCollider = hitCollider; this.hitPoint = hitPoint; this.hitBarPoint = hitBarPoint; }