Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        // Add the time since Update was last called to the timer.
        timer += Time.deltaTime;
        bool attack  = Input.GetButton("Fire1") && (!craftmenu.activeSelf);
        bool canFire = (_equipmentManager.CanFire() && currentWeapon.IsAmmoNeeded());

        if (!attack || !canFire)
        {
            anim.SetBool("attack", false);
        }

        // If the Fire1 button is being press and it's time to fire...
        if (isLocalPlayer && canFire && attack && timer >= currentWeapon.getTimeBetweenBullet())
        {
            // ... shoot the gun  and start animation
            anim.SetBool("attack", true);
            //isAnimationWorking = true;
            if (anim.GetLayerWeight(currentWeapon.GetLayerNumber()) != 1.0f)  // if not active yet

            {
                Debug.LogError("Je passe ici");
                resetWeight();
                anim.SetLayerWeight(currentWeapon.GetLayerNumber(), 1.0f);
            }
            isShooting = true;
            currentWeapon.SetCanHit(isShooting);
        }
        else if (attack && !canFire)
        {
            Debug.LogError("Not enough ammo!");
            playerInfo.DisplayMessage("error", "Pas assez de munitions.");
        }

        if (anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).IsName(currentWeapon.GetLayerName()) && anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).normalizedTime > currentWeapon.GetFiringTime() && isShooting && canFire) // Firing during the animation
        {
            timer = 0f;
            float angle = AimCone.GetAngle(Statistics, PlayerMovement.GetSpeed() / 3) / 2;
            currentWeapon.Fire(angle);
            isShooting = false;
            _equipmentManager.RemoveAmmo();
        }

        /* if(anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).IsName(currentWeapon.GetLayerName()) && anim.GetCurrentAnimatorStateInfo(currentWeapon.GetLayerNumber()).normalizedTime > .99f && isAnimationWorking ) // reset timer when animation is finished
         * {
         *   isAnimationWorking = false;
         *   timer = 0f;
         * }*/

        if (timer >= currentWeapon.getTimeBetweenBullet() * currentWeapon.getEffectsDisplayTime())
        {
            // ... disable the effects.
            currentWeapon.DisableEffects();
        }
    }