Thanks in advance for your help with this. I’m a newbie and am sure there’s something simple I’m doing wrong.
Here’s what I’m trying to achieve:
Player pushes “2” on the keyboard which activates an object. If they push any other key, the object deactivates.
The following script flashes my object for a moment but I want it to be active until another key is pressed.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Button2 : MonoBehaviour
{
[SerializeField] GameObject _object;
private void Update()
{
if (Input.GetKeyDown(KeyCode.Alpha2))
{
_object.SetActive(true);
}
if (!Input.GetKeyDown(KeyCode.Alpha2))
{
_object.SetActive(false);
}
}
}
Thank you very much dstears. That works perfectly.
– Flipperchuck