private void Attack() { Collider[] overlaps = _attackHurtbox.OverlapBox(playerLayer); HashSet <HitboxRoot> rootsHit = new HashSet <HitboxRoot>(); foreach (Collider overlap in overlaps) { _player = overlap.GetComponentInParent <Actor>(); HitboxCollider hitbox = overlap.transform.GetComponent <HitboxCollider>(); DamageType damageType = DamageType.Base; if (hitbox != null) { if (!rootsHit.Contains(hitbox.root)) { rootsHit.Add(hitbox.root); if (hitbox.gameObject.tag == "Weakpoint") { damageType = DamageType.Weakpoint; } hitbox.Hit(new DamageInfo() { amount = _damage, damageTeam = DamageTeam.Enemy, source = actor, damageType = damageType }); } } } StartCoroutine(AttackRoutine()); }
public void Fire() { if (ammo != 0 && !isReload) { StartCoroutine(MuzzleFlareRoutine()); ammo -= 1; RaycastHit hit; Vector3 castDir = _cursorTransform.position - _camera.FirstPersonCam.transform.position; if (Physics.Raycast(_camera.FirstPersonCam.transform.position, castDir, out hit, Mathf.Infinity, enemyLayer)) { Debug.DrawRay(_camera.FirstPersonCam.transform.position, castDir * hit.distance, Color.yellow); HashSet <HitboxRoot> rootsHit = new HashSet <HitboxRoot>(); Actor enemy = hit.transform.gameObject.GetComponentInParent <Actor>(); if (enemy.GetBehaviour <Actor_Enemy>().isShootable) { HitboxCollider hitbox = hit.transform.GetComponent <HitboxCollider>(); DamageType damageType = DamageType.Base; if (hitbox != null) { if (!rootsHit.Contains(hitbox.root)) { rootsHit.Add(hitbox.root); if (hitbox.gameObject.tag == "Weakpoint") { damageType = DamageType.Weakpoint; } hitbox.Hit(new DamageInfo() { amount = _damage, damageTeam = DamageTeam.Any, source = actor, damageType = damageType }); } } } } else { Debug.DrawRay(_camera.FirstPersonCam.transform.position, castDir * 1000, Color.white); Debug.Log("Did not Hit"); } } if (ammo == 0 && !isReload) { Reload(); } }