// 攻击敌人,对敌人造成伤害 private void Atk() { Ray ray = new Ray(hitPoint.position, transform.forward); RaycastHit[] hits = Physics.SphereCastAll(ray, 1f, hitDistance, LayerMask.GetMask("Enemy")); if (hits != null) { foreach (var hit in hits) { ILife life = hit.collider.GetComponent <ILife>(); if (life != null) { life.Reduce(gameObject, power); } } } }
private void PowerHit() { Ray ray = new Ray(hitPoint.position, transform.forward); RaycastHit[] hits = Physics.SphereCastAll(ray, 1f, hitDistance, LayerMask.GetMask("Enemy")); if (hits != null) { foreach (var hit in hits) { ILife life = hit.collider.GetComponent <ILife>(); if (life != null) { life.Reduce(gameObject, power * 2); cinemachineCollisionImpulseSource.GenerateImpulse(new Vector3(1, 2, 0)); } } } }