Пример #1
0
    void Update()
    {
        if (Input.GetAxis("Fire1") == 1)
        {
            ProcessFiring();
        }

        if (previousAmmo != ammo.GetAmmoAmount(ammoType))
        {
            UpdateWeaponUI();
            previousAmmo = ammo.GetAmmoAmount(ammoType);
        }
    }
Пример #2
0
    private void DisplayAmmo()
    {
        int currentAmmoL = ammoSlot.GetCurrentAmmo(ammoType);
        int currentAmmoR = ammoSlot.GetAmmoAmount(ammoType);

        ammoText.text = "Ammo " + currentAmmoL.ToString() + '/' + currentAmmoR.ToString();
    }
Пример #3
0
 void Update()
 {
     if (Input.GetMouseButtonDown(0) && ammoSlot.GetAmmoAmount(ammoType) > 0 && canShoot)
     {
         StartCoroutine(Shoot());
     }
 }
Пример #4
0
 void Start()
 {
     FPSCamera       = Camera.main;
     ammo            = GetComponentInParent <Ammo>();
     animator        = GetComponent <Animator>();
     playerUIHandler = FindObjectOfType <PlayerUIHandler>();
     UpdateWeaponUI();
     previousAmmo = ammo.GetAmmoAmount(ammoType);
 }
    private IEnumerator initialize()
    {
        yield return(new WaitForSeconds(0.2f));

        currentTypeOfAmmo = TypeOfAmmo.Bullets;
        ammo = FindObjectOfType <Ammo>();
        ammo.OnAmmoAmountChanged.AddListener(UpdateAmmoAmount);
        UpdateAmmoAmount(ammo.GetAmmoAmount(currentTypeOfAmmo), currentTypeOfAmmo);

        switcher = FindObjectOfType <WeaponSwitcher>();
        switcher.OnWeaponSwitched.AddListener(UpdateAmmoType);
        UpdateAmmoType(currentTypeOfAmmo);
    }
Пример #6
0
    IEnumerator Shoot()
    {
        canShoot = false;
        if (ammoSlot.GetAmmoAmount(ammoType) > 0)
        {
            muzzleFlashFx.Play();
            RaycastHit hit;
            if (Physics.Raycast(fpsCamera.transform.position, fpsCamera.transform.forward, out hit, range))
            {
                GameObject impact = Instantiate(hitFx, hit.point, Quaternion.LookRotation(hit.normal));
                Destroy(impact, 0.1f);
                EnemyHealth target = hit.transform.GetComponent <EnemyHealth>();
                if (target)
                {
                    target.TakeDamage(attackPower);
                }
            }
            ammoSlot.ReduceAmmoAmount(ammoType);
        }
        yield return(new WaitForSeconds(shotDelay));

        canShoot = true;
    }
    private void UpdateAmmoType(TypeOfAmmo ammoType)
    {
        currentTypeOfAmmo = ammoType;
        Color typeColor;

        switch (ammoType)
        {
        case TypeOfAmmo.Bullets: typeColor = bulletsColor;
            break;

        case TypeOfAmmo.Mana: typeColor = manaColor;
            break;

        default:
            throw new ArgumentOutOfRangeException(nameof(ammoType), ammoType, null);
        }
        AmmoTypeText.text    = ammoType.ToString();
        AmmoTypeText.color   = typeColor;
        AmmoAmountText.color = typeColor;
        UpdateAmmoAmount(ammo.GetAmmoAmount(currentTypeOfAmmo), currentTypeOfAmmo);
    }
Пример #8
0
 private void DisplayAmmo()
 {
     ammoText.text = "Ammo : " + myAmmo.GetAmmoAmount(ammoType).ToString();
 }