- Home /
Question by
coreykadd · Oct 26, 2015 at 11:58 AM ·
soundkey pressed
play car engine sound only when W key is pressed down?
I'm having a problem with my car engine sound. I can get the sound to work but when I stop pressing the W key the sound keeps playing. How do I fix this?
using UnityEngine;
using System.Collections;
public class CarEngine : MonoBehaviour {
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if(Input.GetKeyDown(KeyCode.W))
{
GetComponent<AudioSource>().enabled = !GetComponent<AudioSource>().enabled;
}
}
}
Comment
Your answer