private void CheckForCollision() { // Cast a ray _ray = new Ray(transform.position, transform.forward); float lengthOfRay = _mob.MaxSpeed * Time.deltaTime; Debug.DrawRay(transform.position, transform.forward, Color.white); if (Physics.Raycast(_ray, out _hitInfo, lengthOfRay, LayerMask)) { //print("Collided With " + _hitInfo.collider.gameObject.name); GameObject col = _hitInfo.collider.gameObject; if (col.GetComponent <ShieldController>() != null) { ShieldController shield = col.GetComponent <ShieldController>(); float angle = Vector3.Angle(shield.RotationPoint.forward, -transform.forward); if (angle <= shield.Width) { Damage = shield.ApplyDamage(Damage); } } else if (col.GetComponent <ShipSectionController>() != null) { ShipSectionController c = col.GetComponent <ShipSectionController>(); Damage = c.Ship.ApplyDamage(Damage); } } if (Damage <= 0) { KillSelf(); } }