예제 #1
0
        IEnumerator PushBack(Transform enemyPos)
        {
            float direction = 1;

            if (transform.position.x < enemyPos.position.x)
            {
                direction = -1;
            }

            pushBackTimer = 0;
            animator.SetTrigger("getHit");
            weapon.GetComponent <Animator>().SetTrigger("getHit");
            float currentY = transform.position.y;

            if (weapon.decayTimerActive)
            {
                weapon.decayTimer = 0;
            }
            else
            {
                stash.RemoveCharge("fighter");
            }

            while (pushBackTimer < pushBackDuration)
            {
                rb.velocity = new Vector2(direction * pushBackSpeed * Time.deltaTime,
                                          rb.velocity.y);

                transform.position = new Vector2(transform.position.x, currentY);

                pushBackTimer += Time.deltaTime;

                yield return(null);
            }
        }
예제 #2
0
        public void Throw(Vector2 aimDirection)
        {
            if (weapon.currentWeapon == WeaponType.Unarmed || stash.chargesAmount == 0)
            {
                return;
            }

            float aimAngle = Mathf.Atan2(aimDirection.y, aimDirection.x) * Mathf.Rad2Deg;

            GameObject projectile = Instantiate(weaponToThrow,
                                                originVector, Quaternion.AngleAxis(aimAngle, Vector3.forward));

            projectile.GetComponent <Rigidbody2D>().velocity = aimDirection * throwSpeed * Time.deltaTime;

            stash.RemoveCharge("throw");

            // TO DO: Ensure that speed of projectile is always the same, now matter how far thumbstick is pushed
        }
예제 #3
0
        private void HandleDecayTimerAndFlashing()
        {
            if (!decayTimerActive)
            {
                return;
            }

            float interval = minFlashInterval + decayTimer / decayTime * (maxFlashInterval - minFlashInterval);

            decayTimer -= Time.deltaTime;
            flashed     = Mathf.PingPong(Time.time, interval) > (interval / 2f);

            if (decayTimer <= 0)
            {
                decayTimer       = 0;
                decayTimerActive = false;
                flashed          = false;
                if (stash.chargesAmount != 0)
                {
                    stash.RemoveCharge("weapon");
                }
            }
        }