示例#1
0
        public void ReduceHealthAndShields(float damage)
        {
            //Shields are mandatory for the suppressioon mechanic to work.
            //However, as you may not want the agent to have any sort of regenerating health, you can choose whether or not they will actually block damage or merely work as a recent damage counter.
            if (shieldsBlockDamage)
            {
                if (damage > shields)
                {
                    if (soundScript && myAIBaseScript.HaveCover() && shields > 0)
                    {
                        soundScript.PlaySuppressedAudio();
                    }

                    //Eliminate shields and pass on remaining damage to health.
                    damage -= shields;
                    shields = 0;
                    health -= damage;

                    //If the agent's shields go down, become suppressed (ie: agent will stay in cover as much as possible, and will avoid standing up to fire)
                    myAIBaseScript.ShouldFireFromCover(false);
                }
                else
                {
                    shields -= damage;
                }
            }
            else
            {
                if (damage > shields)
                {
                    if (soundScript && myAIBaseScript.HaveCover() && shields > 0)
                    {
                        soundScript.PlaySuppressedAudio();
                    }

                    //If the agent's shields go down, become suppressed (ie: agent will stay in cover as much as possible, and will avoid standing up to fire)
                    myAIBaseScript.ShouldFireFromCover(false);
                }

                //Do the same amount of damage to shields AND health.
                shields = Mathf.Max(shields - damage, 0);
                health -= damage;
            }

            currentTimeBeforeShieldRegen = timeBeforeShieldRegen;

            //Sound
            if (soundScript)
            {
                soundScript.PlayDamagedAudio();
            }

            if (health > 0 && damage > staggerThreshhold && canStagger && Random.value < staggerOdds && timeTillNextStagger < 0)
            {
                myAIBaseScript.StaggerAgent();
                timeTillNextStagger = timeBetweenNextStaggers;
            }
        }