I'm fairly new to Unity, and I have a script I'm working with that plays two different flashlight sounds (one for the off and one for the on position).
Here's the script I'm currently working with:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class FlashlightClick : MonoBehaviour
{
public Light flashLight;
public AudioSource AudioSource;
public AudioClip soundFlashlightOn;
public AudioClip soundFlashlightOff;
private bool isActive;
void Start ()
{
isActive = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (isActive == false)
{
flashLight.enabled = true;
isActive = true;
AudioSource.PlayOneShot(soundFlashlightOn);
}
else if (isActive == true)
{
flashLight.enabled = false;
isActive = false;
AudioSource.PlayOneShot(soundFlashlightOff);
}
}
}
}
The script creates four variables: Flash Light, Audio Source, Sound FlashLight On, and Sound FlashLight Off.
On the Flash Light variable, I have the flashlight (just the spotlight game object), on Audio Source, I have the FPSController object, and on Sound FlashLight On and Sound FlashLight Off I have the two sounds for the flashlight toggles.
When I start the game, the flashlight is on by default. Any ideas how to modify the script so that my character starts with the flashlight set to off?
Components added to FPSController, NOT FirstPersonCharacter
Thanks in advance for any guidance!