Пример #1
0
    IEnumerator Explode()
    {
        RaycastHit[] hitinfo = Physics.SphereCastAll(transform.position, 50, Vector3.forward, 50, int.MaxValue, QueryTriggerInteraction.UseGlobal);
        foreach (RaycastHit hit1 in hitinfo)
        {
            //If it hits a body of a unit the script continues
            if (hit1.collider.tag == "BodyPart")
            {
                ///Calculates the damage depending on the distance between the explosion and the target
                fractionalDistance = (Mathf.Max(0, 75 - Vector3.Distance(transform.position, hit1.transform.position))) / 75;
                damage             = scaledDamage * fractionalDistance + minimumDamage;
                target             = hit1.transform.GetComponentInParent <OffensivePlaceables>();
                ///Also gets the target's script so it can deal damage

                //checks if the target is an enemy and if so deals damage
                if (target != null && target.currentTeam != currentTeam)
                {
                    enemyUnits.Add(target);
                    target = enemyUnits[0];
                    target.DealDamage(damage);
                    enemyUnits.RemoveAt(0);
                }
            }
        }
        //Waits three seconds until the patricle effect has fully stopped, and then destroys itself.
        yield return(new WaitForSeconds(3f));

        Destroy(gameObject);
    }
Пример #2
0
 //Deal damage to the enemy
 public void Attack(float damage)
 {
     enemy.DealDamage(damage);
 }