示例#1
0
    // Use this for initialization
    void Start()
    {
        FindWeaponParent(transform);
        //Call FindWeaponParent to set the 'parent' Shoot, if it returns false, then stop the rest of Start
        if (parentOriginalShoot != null && !parentOriginalShoot.isPickup)
        {
            parentObject = parentOriginalShoot.gameObject;

            if (!parentObject.GetComponent <BurstShoot>())                       //Check to see if the parent gameObject already has a BurstShoot component attached
            {
                BurstShoot tempShoot = parentObject.AddComponent <BurstShoot>(); //Adding a BurstShoot script to the weapon, and setting tempShoot to it
                tempShoot.bulletsPerBurst = 3;                                   //Setting the bullets per burst of the BurstShoot
                tempShoot.burstFireRate   = .05f;                                //Setting the bursetFireRate of the BurstShoot
                bool increasedMag = false;
                while (parentOriginalShoot.magazineSize % 3 != 0)                //If the original magazine size is not divisible by three, increase it by one until it is (should run only 3 times, max)
                {
                    parentOriginalShoot.magazineSize++;
                    increasedMag = true;
                }
                if (increasedMag)
                {
                    parentOriginalShoot.Reload(true);
                }
                tempShoot.CopyFrom(parentOriginalShoot);     //Copying all the Non-Burst properties into the BurstShoot
                tempShoot.ammo   = parentOriginalShoot.ammo; //Giving the BurstShoot the same ammo object as the original Shoot
                parentAddedShoot = tempShoot;                //Setting parentAddedShoot. The BurstShoot properties won't change, so we don't need to access them anymore
            }
            else //If it does have one attached
            {
                if (parentOriginalShoot.shootType == Shoot.ShootType.BurstShoot)
                //If the parent gameObject is a BurstShoot Object
                {
                    parentAddedShoot = parentObject.AddComponent <SemiAutoShoot>();
                    parentAddedShoot.CopyFrom(parentOriginalShoot);
                    parentAddedShoot.ammo = parentOriginalShoot.ammo;
                }
            }
            parentAddedShoot.enabled    = false;
            parentOriginalShoot.enabled = true;
        }
        else
        {
            Debug.Log("Couldn't find parent with shoot script!");
        }
    }
示例#2
0
 public override void CopyFrom(Weapon weapon)
 {
     base.CopyFrom(weapon);
     if (weapon.weaponType == WeaponType.Gun)
     {
         Shoot tempShoot = (Shoot)weapon;
         try
         {
             BurstShoot tempBurst = (BurstShoot)tempShoot;
             burstFireRate      = tempBurst.burstFireRate;
             bulletsPerBurst    = tempBurst.bulletsPerBurst;
             isProjectile       = tempBurst.isProjectile;
             projectileForce    = tempBurst.projectileForce;
             projectileToBeShot = tempBurst.projectileToBeShot;
             numberOfPellets    = tempBurst.numberOfPellets;
         }
         catch (System.InvalidCastException)
         {
             Debug.LogError("Weapon passed to CopyFrom is not the same as the weapon copying! Could not pass derived class variables");
         }
     }
 }