public virtual void Shoot()
 {
     // Can Shoot?
     if (canShoot)
     {
         // Create a bullet ray from shot origin to forward
         Ray        bulletRay = new Ray(shotOrigin.position, shotOrigin.forward);
         RaycastHit hit;
         // Perform Raycast (Hit Scan)
         if (Physics.Raycast(bulletRay, out hit, range))
         {
             // Try getting enemy from hit
             IKillable killable = hit.collider.GetComponent <IKillable>();
             if (killable != null)
             {
                 // Deal tamage to enemy
                 killable.TakeDamage(damage);
             }
         }
         // Show Line
         StartCoroutine(ShowLine(bulletRay, lineDelay));
         // Reset timer
         shootTimer = 0;
         // Can't shoot anymore
         canShoot = false;
     }
 }
Beispiel #2
0
    public virtual void Shoot()
    {
        //Can shoot
        if (canShoot)
        {
            //create bullet ray
            Ray        bulletRay = new Ray(shotOrigin.position, shotOrigin.forward);
            RaycastHit hit;

            if (Physics.Raycast(bulletRay, out hit, range))
            {
                IKillable killable = hit.collider.GetComponent <IKillable>();
                if (killable != null)
                {
                    //deal damage to enemy
                    killable.TakeDamage(damage);
                }
            }

            StartCoroutine(ShotLine(bulletRay, lineDelay));

            shootTimer = 0;
            //Can't shoot anymore
            canShoot = false;
        }
    }
Beispiel #3
0
    private IEnumerator LightAttack()
    {
        // Make light attack on CD
        m_canLightAttack = false;

        // Shoot out a ray infront of the player
        Ray attackRay = new Ray(this.transform.position, this.transform.forward);

        RaycastHit[] raycastHits;
        // Cast out the ray as a sphere shape in the attack range
        raycastHits =
            Physics.SphereCastAll(attackRay, AttackRadius, AttackRange, AttackingLayer, QueryTriggerInteraction.Ignore);
        Debug.DrawRay(transform.position, transform.forward * AttackRange, Color.blue, 2f, false);

        m_animator.SetBool("IsAttacking", true);
        yield return(new WaitForSeconds(0.5f));

        foreach (RaycastHit hitResult in raycastHits)
        {
            Debug.Log("Hit: " + hitResult.transform.gameObject.name);
            // Do whatever the other object needs to be react
            IKillable killableObj = hitResult.transform.GetComponent <IKillable>();
            if (killableObj != null)
            {
                killableObj.TakeDamage(AttackDmg);
                if (hitResult.transform.tag == "Enemy")
                {
                    killCount++;
                }
            }
        }
        //yield return new WaitForSeconds(0.5f);
        m_animator.SetBool("IsAttacking", false);
        m_canLightAttack = true;
    }
Beispiel #4
0
    public virtual void Shoot()
    {
        //Can shoot?
        if (canShoot)
        {
            // Crete a bul.et ray from shot origin to forward
            Ray        bulletRay = new Ray(shotOrigin.position, shotOrigin.forward);
            RaycastHit hit;
            //Perform raycast
            if (Physics.Raycast(bulletRay, out hit, range))
            {
                //Try geting enemy from hit
                IKillable killable = hit.collider.GetComponent <IKillable>();
                if (killable != null)
                {
                    killable.TakeDamage(damage);
                }
                Player player = hit.collider.GetComponent <Player>();
                if (player)
                {
                    //deal damage to enemy
                }

                //show line
                StartCoroutine(ShowLine(bulletRay, lineDelay));
                //reset timer
                shootTimer = 0;
                //can't shoot anymore
                shootTimer = 0;
                canShoot   = false;
            }
        }
    }
Beispiel #5
0
    protected virtual void OnTriggerEnter(Collider other)
    {
        if (!other.gameObject.CompareTag("Player"))
        {
            IKillable iKillable = other.GetComponent <IKillable>();
            iKillable?.TakeDamage(damage);

            Destroy(this.gameObject);
        }
    }
Beispiel #6
0
 public virtual void Shoot()
 {
     if (canShoot)
     {
         //Create a bullet ray from shot origin to forward
         Ray        bulletRay = new Ray(shotOrigin.position, shotOrigin.forward);
         RaycastHit hit;
         if (Physics.Raycast(bulletRay, out hit, range))
         {
             IKillable killable = hit.collider.GetComponent <IKillable>();
             if (killable != null)
             {
                 killable.TakeDamage(damage);
             }
         }
         //Show line
         StartCoroutine(ShotLine(bulletRay, lineDelay));
         //Reset timer
         shootTimer = 0;
         //cant shoot
         canShoot = false;
     }
 }
 protected virtual void DealDamage(IKillable killable, int damage)
 {
     killable.TakeDamage(damage);
 }