Esempio n. 1
0
        protected override void trigger()
        {
            // Create flash
            GameObject flash = Instantiate(flashPrefab) as GameObject;

            flash.transform.position = barrelEnd.transform.position;
            flash.transform.rotation = Quaternion.LookRotation(barrelEnd.transform.forward, barrelEnd.transform.up);
            flash.transform.SetParent(transform);
            // Launch the projectile
            WeaponProjectile instance = projectiles.popOrCreate(weapon.projectile.prefab.GetComponent <WeaponProjectile>(), barrelEnd.transform.position, Quaternion.identity);

            instance.gameObject.SetActive(true);
            instance.transform.parent = owner.transform.parent;
            instance.gun = this;
            Physics.IgnoreCollision(instance.GetComponent <Collider>(), owner.GetComponent <Collider>());
            if (owner.isHero())
            {
                if (owner.shield != null)
                {
                    Physics.IgnoreCollision(instance.GetComponent <Collider>(), owner.shield.GetComponent <Collider>());
                }
            }
            instance.Launch(barrelEnd.transform.position, owner.transform.forward);
            // Play sound
            playTriggerSound();
            // Count ammo
            ammo--;
        }
Esempio n. 2
0
 public virtual bool returnProjectile(WeaponProjectile projectile)
 {
     projectile.transform.position = transform.position;
     projectile.transform.SetParent(transform);
     if (projectiles.push(projectile))
     {
         projectile.gameObject.SetActive(false);
         return(true);
     }
     else
     {
         Destroy(projectile.gameObject);
         return(false);
     }
 }
Esempio n. 3
0
        protected override void trigger()
        {
            // Muzzleflash
            GameObject flash = Instantiate(flashPrefab) as GameObject;

            flash.transform.position = barrelEnd.transform.position;
            flash.transform.rotation = Quaternion.LookRotation(barrelEnd.transform.forward, barrelEnd.transform.up);
            flash.transform.SetParent(transform);
            // Shot
            float perShot = scatter / fractionAmount;
            float start   = -scatter / 2f;
            float angle   = start;
            float end     = scatter / 2f + 1;
            // Create list to store each fraction of charge
            List <WeaponProjectile> charge = new List <WeaponProjectile>();

            while (angle < end)
            {
                Vector3          direction  = Quaternion.AngleAxis(angle, Vector3.up) * owner.transform.forward;
                WeaponProjectile projectile = projectiles.popOrCreate(weapon.projectile.prefab.GetComponent <WeaponProjectile>(), barrelEnd.transform.position, Quaternion.identity);
                projectile.gameObject.SetActive(true);
                projectile.transform.parent = owner.transform.parent;
                Physics.IgnoreCollision(projectile.GetComponent <Collider>(), owner.GetComponent <Collider>());
                if (owner.isHero())
                {
                    if (owner.shield != null)
                    {
                        Physics.IgnoreCollision(projectile.GetComponent <Collider>(), owner.shield.GetComponent <Collider>());
                    }
                }
                // Ignore collision with other fractions
                foreach (WeaponProjectile other in charge)
                {
                    Physics.IgnoreCollision(projectile.GetComponent <Collider>(), other.GetComponent <Collider>());
                }
                projectile.gun = this;
                projectile.Launch(barrelEnd.transform.position, direction);
                charge.Add(projectile);
                angle = angle + perShot;
            }
            playTriggerSound();
            ammo--;
            charge.Clear();
        }