Beispiel #1
0
    private void shootLaser()
    {
        laserLine.enabled = true;
        laserAudioSource.Play();

        //Draw the laser
        RaycastHit hit;
        float      distance = 0f;

        if (Physics.Raycast(shootingPoint.position, transform.forward, out hit, 100, wallLayerMask))
        {
            distance = hit.distance;
            Vector3 endPoint = shootingPoint.localPosition + Vector3.forward * distance;
            laserLine.SetPosition(0, shootingPoint.localPosition);
            laserLine.SetPosition(1, endPoint);
        }

        //Get and damage colliders;
        laserTimer -= Time.deltaTime;
        if (laserTimer < 0)
        {
            laserTimer = laserTickRate;
            RaycastHit[] hits;
            hits = Physics.RaycastAll(shootingPoint.position, transform.forward, distance, enemyLayerMask);
            foreach (RaycastHit rayHit in hits)
            {
                BaseHealth health = rayHit.collider.GetComponentInParent <BaseHealth>();
                if (health != null)
                {
                    health.TakeDamage(laserDamage);
                }
            }
        }
    }
    void AttackBase()
    {
        timer = 0f;

        if (baseHealth.currentHealth > 0)
        {
            anim.SetBool("Attack", true);
            baseHealth.TakeDamage(attackDamage);
        }
    }
Beispiel #3
0
    // Anything that has health will take mortal damage
    private void OnTriggerStay2D(Collider2D collision)
    {
        if (collision.gameObject.GetComponent <BaseHealth>() != null)
        {
            BaseHealth health = collision.gameObject.GetComponent <BaseHealth>();

            health.isInvincible = false;
            health.TakeDamage(health.maxHealth);
        }
    }
Beispiel #4
0
    IEnumerator ClearWay(Building building)
    {
        BaseHealth    wallHealth = building.GetComponent <BaseHealth>();
        AIInteraction aiInteract = GetComponent <AIInteraction>();

        while (wallHealth.IsAlive)
        {
            wallHealth.TakeDamage(aiInteract.damage, transform);
            yield return(new WaitForSeconds(aiInteract.attackDelay));
        }
        canMove = true;
    }
Beispiel #5
0
 public void Attack()
 {
     Debug.Log("base health : " + baseHealth.currentHealth);
     // If the player has health to lose...
     if (baseHealth.currentHealth > 0)
     {
         Debug.Log("Attacking!");
         // ... damage the base.
         baseHealth.TakeDamage(attackDamage);
         Destroy(gameObject);
     }
 }
Beispiel #6
0
    void Attack(bool isPlayer)
    {
        timer = 0f;

        if (playerHealth.getHealth() > 0 && isPlayer)
        {
            playerHealth.TakeDamage(attackDamage);
        }
        else
        {
            baseHealth.TakeDamage(attackDamage);
        }
    }
Beispiel #7
0
 private void HitTarget()
 {
     if (target.tag == "EnemiesBase" || target.tag == "AlliesBase")
     {
         BaseHealth _base = target.GetComponent <BaseHealth>();
         _base.TakeDamage(this.attackDamage);
     }
     else
     {
         Character character = target.GetComponent <Character>();
         character.DealDamage(this.attackDamage);
     }
     Destroy(this.gameObject);
 }
Beispiel #8
0
    private void PerformAttackOnBase()
    {
        BaseHealth _base = target.GetComponent <BaseHealth>();

        if (attackObject != null && !_base.IsDead())
        {
            animator.Play("Right Throw");
            GameObject rangeAttackObject = (GameObject)Instantiate(attackObject, this.transform);
            rangeAttackObject.transform.Translate(new Vector3(0, 3f, 0));
            rangeAttackObject.GetComponent <RangeAttack>().Seek(this.target, this.attackDamage);
        }
        else if (!_base.IsDead())
        {
            animator.Play("Melee Right Attack 01");
            _base.TakeDamage(this.attackDamage);
        }
        else
        {
            attackTimer = 1.25f;
            target      = null;
        }
    }
Beispiel #9
0
    // Use this for initialization

    public void Attack(BaseHealth target)
    {
        target.TakeDamage(damage, transform);
        StartCoroutine(delayAttack(target));
    }