Exemple #1
0
    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());
    }
Exemple #2
0
 // Start is called before the first frame update
 void Start()
 {
     stateMachine.ChangeState(new StateMove(this.gameObject));
     input          = this.GetComponent <PlayerInput>();
     hitboxCollider = this.GetComponent <HitboxCollider>();
     anim           = this.gameObject.GetComponent <Animator>();
 }
Exemple #3
0
 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();
     }
 }