every thing works as I would like it to except for the hum. it does not turn off.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LightSaber : MonoBehaviour
{
public ParticleSystem particles;
public GameObject redlight;
public AudioClip ignition;
public AudioClip hum;
AudioSource audioSource;
// Start is called before the first frame update
void Awake()
{
particles = GetComponentInChildren<ParticleSystem>();
audioSource = GetComponent<AudioSource>();
}
private void Start()
{
redlight.SetActive(false); //turns light off at start
}
void Update()
{
if (Input.GetKeyDown(KeyCode.R))
{
var em = particles.emission; //emission needs to be off in the inspector.
em.enabled = !em.enabled; //this toggles it on.
redlight.SetActive(!redlight.activeSelf); //this turns the light on and off
audioSource.PlayOneShot(ignition, 0.7f); // sound plays each time you press R
audioSource.PlayOneShot(hum, 0.2f); // this sound comes on but will not turn off.
}
}
}