What I want to have is a power out feature in my flashlight. I have this in c#
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class flashlight : MonoBehaviour {
public Light YourFlashlight;
public AudioClip FlashlightSoundOn;
public AudioClip FlashlightSoundOff;
public AudioSource TheAudioSource;
private bool isActive;
// Use this for initialization
void Start ()
{
isActive = true;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
if(isActive == false) //Flashlight on
{
YourFlashlight.enabled = true;
isActive = true;
TheAudioSource.PlayOneShot(FlashlightSoundOn);
}
else if(isActive == true) //Flashlight off
{
YourFlashlight.enabled = false;
isActive = false;
TheAudioSource.PlayOneShot(FlashlightSoundOff);
}
}
}
}
How can I add a script so if you waste too much battery it will shut down. (makes a challenge of staying alive and conserving battery! :D)