示例#1
0
 void Awake()
 {
     if (!can_attack)
         return;
     health_action = gameObject.GetComponent<HealthAction> ();
     SetHealthActionVariables ();
 }
示例#2
0
    void ApplyDamage(GameObject collidedObject)
    {
        if (collidedObject.tag == collisionObjectiveTag)
        {
            collidedObjectHealth  = collidedObject.GetComponent <HealthAction>();
            collidedObjectRB      = collidedObject.GetComponent <Rigidbody>();
            collidedObjectNavMesh = collidedObject.GetComponent <NavMeshAgent>();

            collidedObjectHealth?.ChangeHealth(-this.damage);

            if (collidedObjectNavMesh != null && collidedObjectNavMesh.enabled)
            {
                collidedObjectNavMesh.enabled = false;
                collidedObjectRB.isKinematic  = false;
                Invoke("ReEnableCollidedObjectNavMesh", 0.25f);
            }


            collidedObjectRB?.AddForce(this.gameObject.transform.forward * knockback, ForceMode.Impulse);
        }

        if (this.selfDestroyOnCollision)
        {
            Destroy(this.gameObject);
        }
    }
        public void Update(int healthModifier, HealthAction healthAction)
        {
            //Only do this if there was an actual Health change
            if (healthModifier != 0)
            {
                if (healthAction == HealthAction.Increase)
                {
                    //Update actual Health
                    this.actualHealth += healthModifier;
                }
                else if (healthAction == HealthAction.Decrease)
                {
                    //Update actual Health
                    this.actualHealth       -= healthModifier;
                    this.lastDamageSustained = healthModifier;
                }
            }


            //Check what should be done
            //If the visible health is more than the actual, decrease the visible
            //If the actual is equal or bigger the visible health, stop or increase the visible health
            if (this.actualHealth < this.visibleHealth)
            {
                float percentageCalculator = 0.01f;

                int calculatedDecrease = (int)Math.Ceiling(this.lastDamageSustained * percentageCalculator);

                this.visibleHealth -= calculatedDecrease;
            }
            else if (this.actualHealth >= this.visibleHealth)
            {
                this.visibleHealth = this.actualHealth;
            }
        }
示例#4
0
 void Awake()
 {
     if (!can_attack)
     {
         return;
     }
     health_action = gameObject.GetComponent <HealthAction> ();
     SetHealthActionVariables();
 }
示例#5
0
        public static int GetRandom(HealthAction healthAction)
        {
            switch (healthAction)
            {
            case HealthAction.Boost:
                return(rnd.Next(10, 25));

            case HealthAction.Reduce:
                return(rnd.Next(0, 20));

            default:
                return(0);
            }
        }
示例#6
0
 public Cat ChangeHealth(HealthAction action)
 {
     _cat.ApplyAction(action);
     return(_cat);
 }