I dunno what Im doing wrong I wrote this toggle script to turn a light on and off but it wont play my sound along with the light. The sound plays on awake but not when i press the input. Im just trying to get work like the switch on a flashlight.
heres the code:
using UnityEngine;
using System.Collections;
public class headlight : MonoBehaviour {
//light toggle on and off
public Light light1;
public AudioClip onswitch;
private AudioSource source;
//
void awake ()
{
source = GetComponent<AudioSource>();
}
/// </summary>
void Update ()
{
if (Input.GetKeyDown ("l"))
{
light1.enabled = !light1.enabled;
source.PlayOneShot(onswitch, 1F);
}
}
}