Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //if we are reloading, we want to be sure to decriment that time, and set active when complete
        if (gunStatus == GunController.gunstatus.Reloading)
        {
            reloadRemain -= Time.deltaTime;

            //if the time is complete, we set it to be active and set the clip
            if (reloadRemain <= 0)
            {
                gunStatus    = GunController.gunstatus.Active;
                shotsRemain  = clipSize;
                reloadRemain = reloadTime;
            }
        }
    }
Exemplo n.º 2
0
    //for now we just want to stick with the get and set

    /*
     * /// <summary>
     * /// This function is used for setting up the gun
     * /// </summary>
     * /// <param name="gunType"> The type of gun we want</param>
     * /// <param name="ammoType"> The type of ammo we want </param>
     * /// <param name="shotsRemain"> The number of shots we start with</param>
     * /// <param name="shootRate">The shooting rate of the gun</param>
     * /// <param name="shootSpeed">The speed the projectiles are shot</param>
     * /// <param name="freeFire">Whether or not the gun starts in freeFire mode</param>
     * public void Initialize(GunController.guntype gunType, GunController.ammotype ammoType, int shotsRemain, float shootRate, float shootSpeed, bool freeFire, )
     * {
     *  this.gunType = gunType;
     *  this.ammoType = ammoType;
     *  this.shotsRemain = shotsRemain;
     *  this.shootRate = shootRate;
     *  this.shootSpeed = shootSpeed;
     *  this.freeFire = freeFire;
     *
     * }
     */
    /// <summary>
    /// We instantiate a shot at the required location of the gun, given by the offset
    /// </summary>
    public void SpawnShot()
    {
        //We want to check how much ammo we have and whether we are in freefire mode
        if (freeFire == true)
        {
            //if it's free fire we don't need to do anything
        }
        else if (gunStatus == GunController.gunstatus.Active && shotsRemain > 0)
        {
            //We want to decriment the shot counter and fire
            shotsRemain -= 1;
        }
        else if (gunStatus == GunController.gunstatus.Reloading)
        {
            //We just want to wait and do nothing, we can do something in the future
            return;
        }
        else if (shotsRemain == 0 && gunStatus == GunController.gunstatus.Active)
        {
            //we want to set the status to reloading, and set the time
            gunStatus = GunController.gunstatus.Reloading;
            return;
        }

        //We want to initialize the shot at the shootLoc, so first we get the prefab
        //GameObject pref;

        /*if (ammoType == (int)GunController.ammotype.norshots)
         * {
         *  pref = Resources.Load<GameObject>("Prefabs/Ammo/Normal Shot");
         * }
         * else
         * {
         *  pref = null;
         * }*/

        GameObject projectile = (GameObject)Instantiate(projectile_prefab, shootLoc.position, shootLoc.rotation);

        //now we want to fire the gun
        projectile.GetComponent <Projectile>().Fire(shootSpeed);
    }