Exemple #1
0
 private void SetupAvailableWeapons()
 {
     //Add all available weapons based on the weapon templates that were set in the inspector.
     //  Each weapon template has a corresponding weapon class, any unrecognised templates wil throw an error
     availableWeapons = new Weapon[availableWeaponTemplates.Length];
     for (int i = 0; i < availableWeaponTemplates.Length; i++)
     {
         if (availableWeaponTemplates[i] is GunWeaponTemplate gunTemplate)
         {
             availableWeapons[i] = new GunWeapon(this, gunTemplate);
         }
         else if (availableWeaponTemplates[i] is MeleeWeaponTemplate meleeTemplate)
         {
             availableWeapons[i] = new MeleeWeapon(this, meleeTemplate);
         }
         else if (availableWeaponTemplates[i] is GrenadeWeaponTemplate grenadeTemplate)
         {
             availableWeapons[i] = new GrenadeWeapon(this, grenadeTemplate);
         }
         else if (availableWeaponTemplates[i] is PrototypeWeaponTemplate prototypeTemplate)
         {
             availableWeapons[i] = new PrototypeWeapon(this, prototypeTemplate);
         }
         else
         {
             Debug.LogError("Unrecognised weapon type at setup: " + availableWeaponTemplates[i].GetWeaponName());
         }
     }
 }
Exemple #2
0
    //Set the charge slider value based on the prototype weapon charge
    private void UpdatePrototypeChargeSlider()
    {
        PrototypeWeapon protoWeapon = weaponHolderPlayer.GetPrototypeWeapon();

        if (sliderPrototypeCharge != null && protoWeapon != null)
        {
            //Get percentage charge by dividing current charge by max charge
            sliderPrototypeCharge.value = protoWeapon.m_charge / protoWeapon.m_prototypeTemplate.GetMaxCharge();
        }
    }
Exemple #3
0
 private void OnTriggerExit(Collider other)
 {
     if (other.CompareTag("Player"))
     {
         //When the player exits the trigger, stop charging the weapon and stop the looping sound
         if (weapon != null)
         {
             weapon.SetCharging(false);
             weapon = null;
             SoundEffectPlayer.instance.StopLoopingSoundEffect(loopSoundId);
         }
     }
 }
Exemple #4
0
    private const string loopSoundId = "starStoneCharge";   //Name of the looping sound played when charging

    private void OnTriggerEnter(Collider other)
    {
        if (other.CompareTag("Player"))
        {
            //When the player enters the trigger, start charging the weapon and playing the charge sound
            weapon = other.gameObject.GetComponent <WeaponHolder>().GetPrototypeWeapon();
            if (weapon != null)
            {
                weapon.SetCharging(true);
                SoundEffectPlayer.instance.PlayLoopingSoundEffect("Charge Loop", true, transform.position, loopSoundId, 1f);
            }
        }
    }