Question by
tobster56 · May 26, 2020 at 04:14 PM ·
lightingcharacter controllerontriggerstayinput.getkey
Light switch using OnTriggerStay not working properly
the problem is that whenever i enter the collider for the switch and press E it sometimes works and it sometimes doesn't if i were to example stay in the exact same location and press E to turn the light on/off i could press it 4 times then the 5th time it would just work for an unknown reason. my player uses a character controller if that helps
public class Generator : MonoBehaviour
{
public GameObject light;
private bool on = false;
void OnTriggerStay(Collider plyr)
{
if (plyr.tag == "Player" && Input.GetKeyDown(KeyCode.E))
{
Debug.Log("switch");
on = !on;
light.SetActive(on);
}
}
}
Comment