Пример #1
0
        /// <summary>
        /// 实例化弹丸, 过程:
        /// 1. 摄像机震动
        /// 2. 实例化弹丸 (5次)
        /// </summary>
        protected override void InstantiateProjectile()
        {
            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.1f, 2f);
            }

            for (var i = 0; i < 5; i++)
            {
                base.InstantiateProjectile();
            }
        }
Пример #2
0
        /// <summary>
        ///  实例化弹丸 (带角度)
        /// </summary>
        protected void InstantiateProjectile(float amount)
        {
            if (CameraShaker.Instance != null && owner.Actor is CommonPlayer)
            {
                CameraShaker.InitShake(0.07f, recoilForce);
            }

            var p = Instantiate(projectile, gunBarrel.position,
                                Quaternion.Euler(new Vector3(0f, 0f, CurrentAngle + amount)));

            p.owner = owner;
        }
Пример #3
0
        /// <summary>
        ///     实例化弹丸
        /// </summary>
        protected virtual void InstantiateProjectile()
        {
            if (CameraShaker.Instance != null && owner.Actor is CommonPlayer)
            {
                CameraShaker.InitShake(0.07f, recoilForce);
            }

            // 设置武器发射子弹的角度 (用随机来模拟后坐力)
            var amount = UnityEngine.Random.Range(-randomAngle, randomAngle);

            var p = Instantiate(projectile, gunBarrel.position,
                                Quaternion.Euler(new Vector3(0f, 0f, CurrentAngle + amount)));

            p.owner = owner;
        }
Пример #4
0
        public void TakeHit()
        {
            hitsTaken = Mathf.Min(hitsTaken + 1, maxHitsNumber);

            // Camera Shake
            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.075f, 1f);
            }

            // Set the right sprite
            if (spriteRenderer != null)
            {
                spriteRenderer.sprite = sprites[hitsTaken];
            }
        }
Пример #5
0
        /// <summary>
        /// 设置收到打击动画
        /// </summary>
        public override void SetTakeHit(int amount)
        {
            if (Fsm.State != States.Normal)
            {
                return;
            }
            base.SetTakeHit(amount);

            //TODO: 被打动画
//            if (!animator.GetCurrentAnimatorStateInfo(0).IsName("TakeHit")) animator.Play("TakeHit");

            QMhelper.SetCurrentHp(Health.health);
            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.075f, 2f);
            }
        }
Пример #6
0
        /// <summary>
        /// 死亡
        /// </summary>
        public override void Die()
        {
            allowMove   = false;
            Health.dead = true;
            allowAttack = false;
            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.25f, 1f);
            }

            Fsm.ChangeState(States.Dead, StateTransition.Overwrite);
            velocity = Vector2.zero;

            Instantiate(ResourceLoader.DeadUi);

            Fsm.ChangeState(States.Normal, StateTransition.Overwrite);

            HidePlayer();
        }
Пример #7
0
        protected virtual void OnEntityEnter(Health health)
        {
            if (healthsDamaged.Contains(health))
            {
                return;
            }

            // camera shake
            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.2f, 1f);
            }

            var damaged = health.TakeDamage(Damage);

            if (damaged)
            {
                healthsDamaged.Add(health);
            }
        }
Пример #8
0
        /// <summary>
        /// 检查场景内敌人, 敌人全部被消灭后开门
        /// </summary>
        private void CheckForEnemiesToOpen()
        {
            if (opened || AreEnemiesAlive())
            {
                return;
            }

            Pickable = true;
            opened   = true;

            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.2f, 1f);
            }

            if (!animator.GetCurrentAnimatorStateInfo(0).IsName("Open"))
            {
                animator.Play("Open");
            }
            AudioManager.Instance.PlayAmbientSoundEffect("DoorOpen");
        }
Пример #9
0
        public void Die()
        {
            // Disable the collider
            if (myCollider != null)
            {
                myCollider.enabled = false;
            }

            // Instantiate the destroy FX
            if (DestroyFX != null)
            {
                Instantiate(DestroyFX, transform.position, Quaternion.identity);
            }

            // Camera Shake
            if (CameraShaker.Instance != null)
            {
                CameraShaker.InitShake(0.12f, 1f);
            }

            // Destroy the gameobject
            Destroy(gameObject);
        }
Пример #10
0
        /// <summary>
        ///     进行伤害
        /// </summary>
        /// <param name="amount">伤害值</param>
        /// <returns>是否被伤害了</returns>
        public bool TakeDamage(int amount)
        {
            if (dead || invincible)
            {
                return(false);
            }

            health = GetDamagedHp(amount);

            MakeDamageNumber(amount);

            Actor.SetTakeHit(amount);

            if (health <= 0)
            {
                dead = true;

                if (Actor is BasePlayer)
                {
                    CameraShaker.InitShake(0.2f, 1f);
                }

                // 静止 Actor 死亡前移动 (死亡延迟 0.5 秒)
                //TODO: 如果不延迟死亡 Actor 无法及时销毁
                Actor.allowAttack = false;
                Actor.allowMove   = false;
                StartCoroutine(DeathEventsRoutine(0.1f));
            }
            else if (becomeInvincibleOnHit)
            {
                invincible       = true;
                _invincibleTimer = invincibleTimeOnHit;
            }

            return(true);
        }