0
\$\begingroup\$

For each of my scenes, I have an empty GameObject _Manager that stores my scripts for setting up the level, keeping track of variables, etc.

On my main screen, I have a play button that isn't instantiated; I simply dragged it into the editor. In my script Main.cs I have a function Play() which calls LoadLevel("Game"). To get my play button to call the Play function, I dragged _Manager into the onClick slot and selected the function. This worked fine and I have a functional play button.

Unfortunately, this is not working for the prefabbed buttons I need to instantaite in my Game scene. In Game.cs I have a function LayoutButtons() which is both public and returns void, yet I am unable to drag _Manager into the slot on my prefabbed button. Even if I do it before converting the button to a prefab, it simply disappears once it becomes a prefab.

I've managed to work around this by putting my LayoutButtons() function in a new script which I attached directly to the prefab, but I'd like to keep the function within Game.cs and attached to my manager object if that's possible.

\$\endgroup\$
1
\$\begingroup\$

You want to Setup play as a public void Play() so when you drag the manager to the click event you can see Play() on the list.

Edit: If you are using a prefabbed button you want to also use a prefabbed manager and drag that into the button click event to work properly.

public void Play()
{
     LoadLevel("Game");
}
\$\endgroup\$
  • \$\begingroup\$ Perhaps my wall of text was confusing. Your code is exactly what I have working. The problem I'm having is that I have other buttons (prefabbed) that don't allow me to do this same thing. \$\endgroup\$ – Matt Jul 12 '15 at 19:52
  • \$\begingroup\$ you would need to have the manager prefabbed and drag the prefabbed version into the click event to call. \$\endgroup\$ – Justin Markwell Jul 12 '15 at 20:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.