示例#1
0
    public override bool Interact(PlayerBase player)
    {
        if (_uses > 0)
        {
            if (isInfinite && player.Ammo + player.AmmoPerOre <= player.MaxAmmo)
            {
                player.Ammo += player.AmmoPerOre;
                inGameHUD.UpdateAmmoText();
            }
            else if (!isInfinite)
            {
                player.HeldAmmo += player.AmmoPerOre;
                inGameHUD.UpdateAmmoText();
            }

            if (!base.Interact(player))
            {
                return(false);
            }

            if (effect != null)
            {
                VFXSpawner.vfx.SpawnVFX(effect, effectDuration, player.transform.position).transform.parent = player.transform;
            }
            if (mineEffect != null)
            {
                RaycastHit hit;
                Ray        ray = new Ray(player.transform.position + VFXPlayerCenterOffset, transform.position - VFXPlayerCenterOffset - player.transform.position);
                if (Physics.Raycast(ray, out hit, 10f, LayerMask.GetMask("Hitbox"), QueryTriggerInteraction.Ignore))
                {
                    VFXSpawner.vfx.SpawnVFX(mineEffect, mineEffectDuration, hit.point).transform.up = -ray.direction.normalized;//hit.normal;
                }
            }
            ChangeState();
        }

        //_animator.SetInteger("stage", _uses);
        //VFX();


        //player.Ammo = Mathf.Clamp(player.Ammo, 0 , player.MaxAmmo); ????
        if (_uses <= 0)
        {
            if (isInfinite)
            {
                _uses = _maxUses;
            }
            else
            {
                //GetComponent<Collider>().enabled = false;
            }
        }

        return(true);
    }
示例#2
0
 protected void Reloading()
 {
     if (reloadCoolDown < 0.01 && heldAmmo > 0) //have ammo to reload and reload time is up
     {
         if (ammo != maxAmmo)                   //full
         {
             _animator.SetBool("reloadAni", true);
             OnReload?.Invoke();
             int tempAmmo = heldAmmo + ammo;
             if (tempAmmo > maxAmmo) //can't hold all the ammo
             {
                 ammo     = maxAmmo;
                 heldAmmo = tempAmmo - maxAmmo;
             }
             else
             {
                 ammo     = tempAmmo;
                 heldAmmo = 0;
             }
             inGameHUD.UpdateAmmoText();
             inGameHUD.DisplayReloadCooldown();
         }
     }
     if (reloadCoolDown < reloadCoolDownTime)
     {
         reloadCoolDown += Time.deltaTime;
     }
     else
     {
         _animator.SetBool("reloadAni", false);
         currentState = PlayerState.Neutral;
     }
 }