Example #1
0
        /// <summary>
        /// Shooting system processing.
        /// </summary>
        protected virtual IEnumerator ShootingProcessing()
        {
            WaitForSeconds    updateDelay = new WaitForSeconds(delay);
            WaitForEndOfFrame endOfFrame  = new WaitForEndOfFrame();

            while (true)
            {
                if (!weaponReloading.BulletsIsEmpty() && !weaponReloading.IsReloading())
                {
                    if (fireMode == Mode.Free && UInput.GetButton(INC.ATTACK) || fireMode == Mode.Single && UInput.GetButtonDown(INC.ATTACK))
                    {
                        DoShoot();
                        yield return(updateDelay);
                    }
                    else if (fireMode == Mode.Queue && UInput.GetButtonDown(INC.ATTACK))
                    {
                        for (int i = 0; i < queueCount; i++)
                        {
                            DoShoot();
                            weaponAnimator.SetAttack(1);
                            yield return(endOfFrame);

                            weaponAnimator.SetAttack(-1);
                            yield return(updateDelay);
                        }
                    }
                }
                else if (UInput.GetButtonDown(INC.ATTACK))
                {
                    AudioClip sound = soundProperties.GetRandomEmptySound();
                    if (sound != null)
                    {
                        audioSource.PlayOneShot(sound);
                    }
                    weaponAnimator.SetAttack(0);
                    yield return(endOfFrame);

                    weaponAnimator.SetAttack(-1);
                }
                yield return(null);
            }
        }
        /// <summary>
        /// Update is called every frame, if the MonoBehaviour is enabled.
        /// </summary>
        protected virtual void Update()
        {
            Vector3 worldDeltaPosition = navMeshAgent.nextPosition - transform.position;

            float   dy            = Vector3.Dot(transform.forward, worldDeltaPosition);
            float   dx            = Vector3.Dot(transform.right, worldDeltaPosition);
            Vector2 deltaPosition = new Vector2(dx, dy);

            float smooth = Mathf.Min(1.0f, Time.deltaTime / 0.15f);

            smoothDeltaPosition = Vector2.Lerp(smoothDeltaPosition, deltaPosition, smooth);

            if (Time.deltaTime > 1e-5f)
            {
                velocity = smoothDeltaPosition / Time.deltaTime;
            }

            animator.SetFloat(SPEED_HASH, velocity.y);
            animator.SetFloat(DIRECTION_HASH, velocity.x);
            animator.SetBool(CROUCH_HASH, behaviour.IsCrouch());
            animator.SetBool(SHOOT_HASH, attackCallbacks.IsAttacking());
            animator.SetBool(RELOAD_HASH, weaponReloading.IsReloading());
        }