Question by
wittledemon · May 01, 2020 at 08:27 PM ·
audioxboxcontroller
Need Help with Code (XBox 360 Controller Pad Help)
I want to make it so the audio plays when the direction is pressed but it seems to only play after the button is released. Can someone tell me what I am doing wrong please?
public class SetCursorActive : MonoBehaviour
{
[SerializeField] GameObject[] activateCursor;
// Start is called before the first frame update
void Start()
{
activateCursor[0].SetActive(true);
activateCursor[1].SetActive(false);
}
// Update is called once per frame
void Update()
{
if (Input.GetAxis("Vertical") > 0)
{
activateCursor[0].SetActive(true);
activateCursor[0].GetComponent<AudioSource>().Play();
activateCursor[1].SetActive(false);
}
else if (Input.GetAxis("Vertical") < 0)
{
activateCursor[0].SetActive(false);
activateCursor[1].SetActive(true);
activateCursor[1].GetComponent<AudioSource>().Play();
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Trying to get full-auto fire for a gun in my game. 0 Answers
Best way to get code to run at very precise timing? 0 Answers
How to use Native Audio Plugin SDK in iOS 0 Answers
audio import errors in webGL 1 Answer
How to set up the right controller stick 0 Answers