UnityScripterAI
Discord ↗
Link Copied to Clipboard
×
"Interactable lever after pressing E"
using UnityEngine; public class InteractableLever : MonoBehaviour { public GameObject lever; public float interactionDistance = 3f; private bool isPlayerInRange = false; private bool leverActivated = false; void Update() { if (isPlayerInRange && Input.GetKeyDown(KeyCode.E) && !leverActivated) { ActivateLever(); } } void OnTriggerEnter(Collider other) { if (other.CompareTag("Player")) { isPlayerInRange = true; } } void OnTriggerExit(Collider other) { if (other.CompareTag("Player")) { isPlayerInRange = false; } } void ActivateLever() { // Add your lever activation logic here leverActivated = true; Debug.Log("Lever activated"); } }