Exemple #1
0
    //Coroutine that reloads smg
    private IEnumerator ChangeMagazine()
    {
        if (currentMagazineCount > 0)
        {
            //call the method in the broker to invoke the reload event for the hud controller
            ReloadWeaponBroker.CallWeaponIsReloading();

            //Play Reload Sound
            smgSound.PlayOneShot(smgReloadClip);

            yield return(new WaitForSecondsRealtime(smgReloadSpeed));

            currentMagazineCount--;
            smgIsReloading    = false;
            bulletsInMagazine = 30;

            //Update bullet and magazine count on HUD
            AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, smgMagazineSize);
            AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentMagazineCount);
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentMagazineCount);

            //  Debug.LogError("SMG RELOADED");

            ReloadWeaponBroker.CallWeaponFinishedReloading();
        }
        else
        {
            Debug.LogError("SMG OUT OF AMMO");

            ReloadWeaponBroker.CallWeaponFinishedReloading();
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentMagazineCount);
        }
    }
Exemple #2
0
 private void OnEnable()
 {
     //if player interrupted the reload
     smgIsReloading = false;
     AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, smgMagazineSize);
     AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentMagazineCount);
 }
Exemple #3
0
    //Shooting the Pistol
    private void ShootRocket()
    {
        if (rocketsInMagazine > 0 && launcherIsReloading == false)
        {
            //Play Sound of rocket launcher shooting
            rocketSound.PlayOneShot(rocketShotClip);

            //Instantiate the Rocket prefab at the firepoint's gameObject position
            GameObject  rocketPrefab    = Instantiate(rocket, firePoint.position, firePoint.rotation);
            Rigidbody2D rocketRigidbody = rocketPrefab.GetComponent <Rigidbody2D>();
            rocketRigidbody.AddForce(firePoint.right * rocketForce, ForceMode2D.Impulse);

            //Set the rocket Color to black
            SpriteRenderer rocketSprite = rocketPrefab.GetComponent <SpriteRenderer>();
            rocketSprite.color = Color.black;

            rocketsInMagazine = 0;

            //Update bullet count on HUD
            AmmoDisplayBroker.CallUpdateAmmoOnHud(rocketsInMagazine, rocketsInMagazine); //totalRockets used to be "rocketsInMagazine". Because now the HUD shows 1/10 instead of 1/1 in the ammo counter. But it turns red on critical ammo. Which to keep?
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentRockets);
        }
        else
        {
            rocketSound.PlayOneShot(rocketEmptyClip);
        }
    }
Exemple #4
0
    private IEnumerator reloadRocket()
    {
        if (currentRockets > 0)
        {
            // Play Sound of rocket launcher reloading
            rocketSound.PlayOneShot(rocketReloadClip);

            //call brokers method weapon is reloading
            ReloadWeaponBroker.CallWeaponIsReloading();

            yield return(new WaitForSecondsRealtime(rocketReloadSpeed));

            currentRockets--;
            launcherIsReloading = false;
            rocketsInMagazine   = 1;

            //Update bullet and magazines count on HUD
            AmmoDisplayBroker.CallUpdateAmmoOnHud(rocketsInMagazine, rocketsInMagazine);
            AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentRockets);
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentRockets);

            ReloadWeaponBroker.CallWeaponFinishedReloading();
        }
        else
        {
            Debug.Log("NO AMMO LEFT. RUN !!!");

            ReloadWeaponBroker.CallWeaponFinishedReloading();
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentRockets);
        }
    }
Exemple #5
0
    private IEnumerator ChangeMagazine()
    {
        if (currentMagazineCount > 0)
        {
            //Pistol reload SOUND
            pistolSound.PlayOneShot(pistolReloadClip);

            //Update the HUD to notify the player that the gun is reloading
            ReloadWeaponBroker.CallWeaponIsReloading();

            currentMagazineCount--;
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentMagazineCount);

            //Wait for reload time
            yield return(new WaitForSecondsRealtime(pistolReloadSpeed));

            pistolIsReloading = false;
            bulletsInMagazine = magazineSize;

            AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, magazineSize);
            AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentMagazineCount);

            ReloadWeaponBroker.CallWeaponFinishedReloading();
        }
        else
        {
            Debug.Log("NO AMMO LEFT. RUN !!!");

            ReloadWeaponBroker.CallWeaponFinishedReloading();
            AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentMagazineCount);
        }
    }
Exemple #6
0
    //Shooting the Pistol
    private void ShootPistol()
    {
        if (bulletsInMagazine > 0)
        {
            //Play Pistol Shooting Sound
            pistolSound.PlayOneShot(pistolShotClip);

            //remove 1 bullet from the magazine
            bulletsInMagazine--;

            //invoke event to update ammo count on HUD
            AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, magazineSize);

            //Instantiate the bullet prefab at the firepoint's gameObject position
            GameObject  bulletPrefab    = Instantiate(bullet, firePoint.position, firePoint.rotation);
            Rigidbody2D bulletRigidbody = bulletPrefab.GetComponent <Rigidbody2D>();
            bulletRigidbody.AddForce(firePoint.right * bulletForce, ForceMode2D.Impulse);

            //Set the bullet Color to red
            SpriteRenderer bulletSprite = bulletPrefab.GetComponent <SpriteRenderer>();
            bulletSprite.color = Color.red;
        }
        else
        {
            //WEAPON EMPTY SOUND
            pistolSound.PlayOneShot(pistolEmptyClip);
        }
    }
Exemple #7
0
    // Start is called before the first frame update
    void Start()
    {
        rocketSound = GetComponent <AudioSource>();

        rocketsInMagazine = 1;
        //Update bullet count and total rockets on HUD
        AmmoDisplayBroker.CallUpdateAmmoOnHud(rocketsInMagazine, rocketsInMagazine);
        AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentRockets);
    }
Exemple #8
0
    // Start is called before the first frame update
    void Start()
    {
        pistolSound = GetComponent <AudioSource>();

        bulletsInMagazine = magazineSize;

        //Update ammo and magazine count on HUD
        AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, magazineSize);
        AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentMagazineCount);
        AmmoDisplayBroker.CallUpdateMagazinesOnStore(weaponIndex, currentMagazineCount);
    }
Exemple #9
0
    // Start is called before the first frame update
    void Start()
    {
        smgSound     = GetComponent <AudioSource>();
        lineRenderer = GetComponent <LineRenderer>();

        lineRenderer.SetPosition(1, firePoint.position);

        //set initial bullets in magazine
        bulletsInMagazine = smgMagazineSize;

        //Update bullet count on HUD
        AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, smgMagazineSize);
        AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentMagazineCount);
    }
Exemple #10
0
    //Method that shoots ray for the SMG
    private void ShootSMG()
    {
        if (bulletsInMagazine > 0)
        {
            //play smg shot sound
            smgSound.PlayOneShot(smgShotClip);


            //SHOOT
            RaycastHit2D smgHit = Physics2D.Raycast(firePoint.position, firePoint.right, smgRange);
            lineRenderer.SetPosition(0, firePoint.position);
            Vector3 mousePosition = Camera.main.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z - Camera.main.transform.position.z));
            lineRenderer.SetPosition(1, (mousePosition));
            bulletsInMagazine--;

            //Update bullet count on HUD
            AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, smgMagazineSize);

            //if enemy hit damage it
            if (smgHit)
            {
                Enemy enemyController = smgHit.collider.gameObject.GetComponent <Enemy>();
                if (enemyController != null)
                {
                    enemyController.TakeDamage(smgDamage);
                }
            }
        }
        else
        {
            //PLAY EMPTY GUN SOUND CLICK CLICK CLICK
            smgSound.PlayOneShot(smgEmptyClip);
        }


        // Debug.DrawRay(transform.position, transform.right * smgRange, Color.red);
        Debug.Log("SMG NEW BULLET");
    }
Exemple #11
0
    //?????????????  private Vector3 mouseAimLocation; need to apply AOE DAMAGE with the launcher



    private void OnEnable()
    {   //if player interrupted the reload this is a check to see if the gun had bullets inside
        launcherIsReloading = false;
        AmmoDisplayBroker.CallUpdateAmmoOnHud(rocketsInMagazine, rocketsInMagazine);
        AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentRockets);
    }
Exemple #12
0
 private void OnEnable()
 {   //if player interrupted the reload this is a check to see if the gun had bullets inside the magazine.
     pistolIsReloading = false;
     AmmoDisplayBroker.CallUpdateAmmoOnHud(bulletsInMagazine, magazineSize);
     AmmoDisplayBroker.CallUpdateMagazinesOnHud(currentMagazineCount);
 }