I have a string in another script which gets updated every time the player switches weapons. Its purpose is to let my PlayerShoot script know which weapon we have equipped and then play the according sound. However, my code does not throw any errors although the sounds are not playing. I have tested the sound by placing the CmdPlayAwpShootSound(); and the CmdPlayTecShootSound();lines in the Start() function and the sounds played.
String we are trying to access:
public string currentHolder;
void Start ()
{
currentHolder = "awpweaponHolder";
EquipAwpWeapon(primaryWeapon);
}
void Update()
{
if(Input.GetAxis("WeaponSwitch") >0f)
{
currentHolder = "tecweaponHolder";
EquipTecWeapon(secondaryWeapon);
Debug.Log("switched weapon");
}
else if (Input.GetAxis("WeaponSwitch")<0f)
{
currentHolder = "awpweaponHolder";
EquipAwpWeapon(primaryWeapon);
Debug.Log("switched weapon back");
}
}
PlayerShoot script:
void Update ()
{
currentWeapon = weaponManager.GetCurrentWeapon();
if (PauseMenu.IsOn)
return;
if (currentWeapon.fireRate <= 0f)
{
if (Input.GetButtonDown("Fire1") && weaponManager.currentHolder == "awpweaponHolder")
{
Shoot();
CmdPlayAwpShootSound();
Debug.Log("play awp sound");
}else if (Input.GetButtonDown("Fire1") && weaponManager.currentHolder == "tecweaponHolder")
{
Shoot();
CmdPlayTecShootSound();
Debug.Log("play tec sound");
}
} else