c# script help

Hi i am a noob! ok so i have an object collider which i want to have an action when the player is inside, and not while the player is outside of the collider. Thanks for the help in advance!

public BoxCollider object1;


       
    void Start()
    {
        object1.enabled = false;
       
    }
   
    void OnGUI()
    {
       
    }
   
    void TriggerEvent1(Collider other)
    {

        if (other.gameObject.name == "object1")
        {
            object1.enabled = true;
        }

        if (other.gameObject.name != "object1")
        {
            object1.enabled = false;
        }

        while(object1.enabled = true)
        {
            Input.GetKeyDown("e");
            print("click");
        }

    }

2243003–149740–SearchArea.cs (506 Bytes)

Assuming this is using 3d colliders, try replacing
void TriggerEvent1(Collider other)
with
void OnTriggerStay(Collider other)

2 Likes

You also want to delete OnGUI. The performance cost of empty OnGUI statements is surprisingly high.

1 Like

Thank you both of you! :slight_smile: