my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Flashlight : MonoBehaviour
{
[SerializeField] GameObject FlashlightLight;
private bool FlashlightActive = false;
// Start is called before the first frame update
void Start()
{
FlashlightLight.gameObject.SetActive(false);
Debug.Log("flashlight off begining");
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F))
{
if (FlashlightActive == false)
{
FlashlightLight.gameObject.SetActive(true);
FlashlightActive = true;
Debug.Log("F key is pressed Flashlight ON");
}
else
{
FlashlightLight.gameObject.SetActive(false);
FlashlightActive = false;
Debug.Log("F key is pressed Flashlight OFF");
}
}
}
}
I want it where when I press the key “f” the flashlight turns on or off.
I have tried multiple different ways of doing this such as changing it to: Input.GetButtonDown("Submit")
(I changed “Submit” to equal “f”)
I have also tried getting rid of the “KeyCode” portion of the code and putting quotations around “f”
I expected this to simply turn on and off the spotlight but clearly it did not. So then I added Debug.Log statements to see if it was detecting the key press at all and it was not. I also have no errors at all. I was following a YouTube tutorial and I have the exact same code as him and his worked.