Exemple #1
0
    void FixedUpdate()
    {
        if (Input.GetMouseButtonDown(0))         //TODO cooldown
        {
            //Consume blood for moving
            ConsumeBlood(bloodCost, "Attack");

            //Copy list to prevent concurrent modifications
            List <GameObject> attackTargets = new List <GameObject>();
            attackTargets.AddRange(areaOfAttack.objectsInArea);

            //Play attack audio
            audioData.Play(0);

            //Loop targets
            foreach (GameObject target in attackTargets)
            {
                //Damage targets
                DamageData damageData = target.GetComponent <DamageData>();
                if (damageData != null)
                {
                    damageData.Attack(damage, gameObject);
                }
            }
        }
    }
    protected override void onHit(DamageData damageData, float collisionSpeed)
    {
        float damage = ScaleDamageForSpeed(collisionSpeed);

        Debug.Log("Bullet: Impacting '" + damageData.gameObject + "' for '" + damage + "' damage points");

        damageData.Attack(damage, shooter);
    }
 protected virtual void onHit(DamageData damageData, float collisionSpeed)
 {
     collisionSpeed = Mathf.Abs(collisionSpeed);
     if (collisionSpeed > collisionMinSpeed)
     {
         float damage = ScaleDamageForSpeed(collisionSpeed);
         Debug.Log("CollisionDamage: Impacting '" + damageData.gameObject + "' for '" + damage + "' damage points with a speed of " + collisionSpeed);
         //Attack entity
         damageData.Attack(damage, gameObject);
     }
 }