So, I have an elevator prefab with a button. The button has a script that raises and lowers the elevator platforms.
There are 2 elevator platforms, and 4 total control panels.
ButtonA1
ButtonA2
These are linked to Elevator A in the script (drag and drop into the script attribute)
ButtonB1
ButtonB2
These are linked to Elevator B in the script (drag and drop into the script attribute).
All the buttons move both elevators, no mater what. I’ve deleted the button prefab and just made a new object with the script attached - same thing. I’ve tried everything short of writing a custom script for each elevator, which isn’t right, as it’s the same exact script.
It was my understanding that it only fired scripts attached to the hit object. You’re saying it fires every instance of the script in the scene, with their overrides?
More to the point, how would I get it to only look at it’s own scripts and ignore the others? I could make item tags, but that would just invalidate the overrides.
EDIT - I just went ahead and used tags. Looks like that method is not uncommon.
Update function is run on each game tick, regardless of anything that’s happening.
If you wanted it to just check that object, you could put a collider on it and the OnMouse functions, and that would only call the button that was clicked.
Alternatively, the raycast hit returns the object that was hit, and so you could compare it with the object that the script is attached to.