Esempio n. 1
0
    public void Fire()
    {
        if (Time.time > this.lastShotTime + shotDelay)
        {
            // create projectile object
            GameObject clone = Instantiate(bulletPrefab, barrelTip.transform.position, gameObject.transform.rotation) as GameObject;

            // Hack! Make the rockets home in on targets.
            Rocket_Behavior rb = clone.GetComponent <Rocket_Behavior>();
            if (rb)
            {
                rb.target = this.target.gameObject;
            }

            // set the damage on the bullet
            // TODO: perhaps set a reference to the turret instead of
            // passing around the damage value.
            Bullet_Behavior b = clone.GetComponent <Bullet_Behavior>();
            b.turret = this;
            b.SetDamage(this.damage);

            animator.SetTrigger("Fire");
            this.lastShotTime = Time.time;

            AudioSource aud = GetComponent <AudioSource>();
            aud.Stop();
            aud.Play();
        }
    }
Esempio n. 2
0
 void OnTriggerExit2D(Collider2D thing)
 {
     if (thing.tag == "enemy")
     {
         parentInfo.zombiesInRange.Remove(thing.gameObject);
     }
     else if (thing.tag == "Projectile")
     {
         // project tile has left the range of the turret so explode/remove object
         Bullet_Behavior bb = thing.gameObject.GetComponent <Bullet_Behavior>();
         Turret          t  = this.gameObject.transform.parent.gameObject.GetComponent <Turret>();
         if (bb.turret == t)
         {
             bb.Explode(null);
         }
     }
 }