ToggleActiveState with OnTriggerExit?

I’m brand new to Unity, though I’ve read a lot of Q&A and tutorials and watched a lot of videos before I started, and did a microgame, but this will be the first script I will have actually created and typed up myself.

With objects in the scene named:
Ceiling Bulb
Motion Sensor
User Avatar

Placing a box collider trigger that is essentially a flat plane across the doorway, I want the OnTriggerExit to toggle state of the light only on collision with User Avatar. It doesn’t have to care which way you are going through or if it is on or off, as long the Toggle Active State right-click option I have in the editor can also be activated by script. Later when I’ve got more experience I can add an if check to see if the room is occupied before turning off on exit.

This is ultra trivial. If you did this:

Then it sounds like you failed to do them meaningfully. WATCHING tutorials is not a thing and has ZERO value.

Tutorials and example code are great, but keep this in mind to maximize your success and minimize your frustration:

How to do tutorials properly, two (2) simple steps to success:

Tutorials are a GREAT idea. Tutorials should be used this way:

Step 1. Follow the tutorial and do every single step of the tutorial 100% precisely the way it is shown. Even the slightest deviation (even a single character!) generally ends in disaster. That’s how software engineering works. Every step must be taken, every single letter must be spelled, capitalized, punctuated and spaced (or not spaced) properly, literally NOTHING can be omitted or skipped.

Fortunately this is the easiest part to get right: Be a robot. Don’t make any mistakes.
BE PERFECT IN EVERYTHING YOU DO HERE!!

If you get any errors, learn how to read the error code and fix your error. Google is your friend here. Do NOT continue until you fix your error. Your error will probably be somewhere near the parenthesis numbers (line and character position) in the file. It is almost CERTAINLY your typo causing the error, so look again and fix it.

Step 2. Go back and work through every part of the tutorial again, and this time explain it to your doggie. See how I am doing that in my avatar picture? If you have no dog, explain it to your house plant. If you are unable to explain any part of it, STOP. DO NOT PROCEED. Now go learn how that part works. Read the documentation on the functions involved. Go back to the tutorial and try to figure out WHY they did that. This is the part that takes a LOT of time when you are new. It might take days or weeks to work through a single 5-minute tutorial. Stick with it. You will learn.
Step 2 is the part everybody seems to miss. Without Step 2 you are simply a code-typing monkey and outside of the specific tutorial you did, you will be completely lost. If you want to learn, you MUST do Step 2.

Of course, all this presupposes no errors in the tutorial. For certain tutorial makers (like Unity, Brackeys, Imphenzia, Sebastian Lague) this is usually the case. For some other less-well-known content creators, this is less true. Read the comments on the video: did anyone have issues like you did? If there’s an error, you will NEVER be the first guy to find it.

Beyond that, Step 3, 4, 5 and 6 become easy because you already understand!

The purpose of this forum is to assist people who are ready to learn by doing, and who are unafraid to get their hands dirty learning how to code, particularly in the context of Unity3D.

This assumes you have at least written and studied some code and have run into some kind of issue.

If you haven’t even started yet, go check out some Youtube videos for whatever game design you have in mind. There are already many examples of the individual parts and concepts involved, as there is nothing truly new under the sun.

If you just want someone to do it for you, you need go to one of these places:

https://forum.unity.com/forums/commercial-job-offering.49/

https://forum.unity.com/forums/non-commercial-collaboration.17/

A. Thank you. I always appreciate feedback, and someone just doing it for me would be … undesired unless they are explaining how each piece connects. This is one very simple piece that I just need to understand properly. My ideal outcome here would be someone linking me to the right tutorial that covers what I’m trying to do, since my search strings aren’t finding the right tutorial.
B. I miss-spoke, so let me clarify: I did Step 1, but not Step 2. I haven’t found one doing the same function with different sets of objects to figure out the interconnection between the script and the unity objects, both those the script is not attached to and those it is. I can understand the scripting concepts themselves as a standalone script from other experience, but that was in self-contained situations - all the code was in the same file. I haven’t been able to find a tutorial covering the specific set of functions I am trying to use referencing more than the object is on, so I’ve done step 1 with several other tutorials that each had one piece of the whole puzzle.
C. I’m not making a game, just an copy of my home I can test remodel/redecorate ideas in. The script I am asking about/making now is just so I learn how to correctly create and link a script of my own making to a scene of my own making, using more than a single function at once. Then I should be able to use that knowledge as a base to create all the different trigger and check combinations I’ll actually need to do the rest.
Right now I’m thinking once I figure out scripting, I’ll make a box collider the size of each room for an occupancy check that will be called when someone crosses a doorway plane that is a separate box collider, so the light comes on if it is off, goes off if it is on and after the ontriggerexit there is no occupancy, but stays on if there is still someone in the room. There may well be better ways to accomplish that set of outcomes, but I’m expecting that this way will teach me to fully understand how each of those pieces work best.

To clarify, I’ve found a lot of OnTriggerEnter and OnTriggerExit, and of light on and light off being triggered, but no ToggleActiveState used instead of “set to on” or “set to off” and none covering colliders that only detect collisions with specific objects.

Thank you again, the second half (doing tutorials by some of the content creators you listed rather than … the others I had been) dealt with some of the questions, and making repeated changes to see the change in error code eventually answered most of the other questions - the biggest was that none of the functions in use reference the exterior object name precisely, that link is handled in the GUI and ignored by the script.

So the answer there is, no, it doesn’t matter if I call it johnDoe in the script, even though all the tutorials I’ve seen use name matching conventions.
The other answer, to the ToggleActiveState function question, is combining the ! (not) operator with set active state operation.