- Home /
Using OnClick() with an empty GameObject
I've used this interface before, but when I click the browse button next to the None (Object), I can't seem to find the GameObject (called gameController) where I keep the script I want to reference. gameController is composed only of a transform and the script I'm trying to reference.
Why can't I (and how do I) reference that GameObject from here? I'm fairly new to Unity, so be suspicious of me not understanding how OnClick() works.
Cheers!
Answer by Bunny83 · Jul 22, 2016 at 09:22 AM
Well, you usually simply link the gameobject in the inspector by dragging it from the hierarchy window onto that object field.
However the ObjectBrowser should work as well. The ObjectBrowser has two tabs at the top to switch between assets and scene objects.
Also keep in mind that Prefabs (objects in the project view) can't reference objects in a scene (hierarchy view). So if this OnClick event is in a script attached to a prefab you can't assign scene objects. Prefabs are assets and are accessible and "linkable" across the whole project. Objects in a scene can only be referenced by other objects in the same scene.
Right, I'm using a prefab, so that must be the issue. $$anonymous$$now any way around this?