key to enable/disable
Sounds simple enough. I use a footsteps system ( different footsounds for different materials) that I want to completely turn off for when my character is sneaking ( as opposed to running, jumping walking etc). My script seems to work...somewhat, in that for the most part the footstep sounds stop but not entirely because if when I use the arrow keys to steer the character a footsound is heard. So, I press right shift key to get character to sneak and disable footsounds, releasing the key turns footsound back on. But while the right shift key is down, pressing another key ( arrow keys to steer character) it seems to enable the footsound for that instant I pressed the arrow key down.
using UnityEngine;
using System.Collections;
public class TurnOnFootsteps : MonoBehaviour {
void Update() {
if (Input.GetKeyUp(KeyCode.RightShift))
GetComponent<AdvFootstepSystem>().enabled = true;
if (Input.GetKeyDown(KeyCode.RightShift))
GetComponent<AdvFootstepSystem>().enabled = false;
}
}
Your answer
Follow this Question
Related Questions
Unity 3D #C Nightvision does not want to switch on or off. 0 Answers
Teleporting player on key press 1 Answer
Stop velocity on Keydown for certain time 1 Answer
Bug in loop while, and Event with Keyboard 1 Answer
Keypresses blocking each other. 0 Answers