- Home /
Other
problem with GetAxisRaw (using joystick trigger)
Hello. I am a complete newbie with joysticks and faced a weird problem. I want to bind the right trigger of the joystick to the primary attack. I took my script that worked great with joystick buttons and changed GetButtonDown to GetAxisRaw. Now When I hit the trigger, I got the desired result, but not everything is so smooth. If you look at my script, you will see that if the ammo runs out, then the sound corresponding to that should be played.
if ((Mathf.Round(Input.GetAxisRaw("PrimaryAttack")) < 0) && Time.time > nextFire)
{
if (currentAmmo > 0)
{
foreach (var shotSpawn in shotSpawns)
{
nextFire = Time.time + fireRate;
PoolManager.Pools["PlayerWeapon"].Spawn(bullet, shotSpawn.position, shotSpawn.rotation);
currentAmmo = currentAmmo - 1;
weaponSlider.value = currentAmmo;
}
}
else
{
if (!outOfAmmoSound.isPlaying)
outOfAmmoSound.Play();
}
}
But in fact, this sound is played every time I hit the trigger. The impression is that there is no check for ammo at all. This sound is always played (there is ammo or no ammo). It does not play only if part of this script is completely removed. Can anyone tell me what could be wrong? I complitely dont understand what is goin on:(
Answer by eneIr · May 28, 2021 at 10:41 AM
You can add another sound and add [newSound].Play() below the if(currentAmo > 0) statement to check whether [newSound] or the outOfAmmoSound will be played.
Answer by DYV · May 28, 2021 at 11:06 AM
thank you for the answer. I have found what was wrong. I had two different attacks tied to one trigger. The second weapon had no cartridges and it gave that sound. Sorry and thank you again
Follow this Question
Related Questions
Animation Trigger is saved even if it is not used immediately. 1 Answer
OnTriggerEnter() is occasionally not occurred 1 Answer
How can i detect by script when a character enter a hole in object ? 1 Answer
In-Game Tutorial with special actions in special areas. (Shooter) 0 Answers
Void OnTriggerEnter not working 1 Answer