Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
up vote 1 down vote accepted

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");
}
share|improve this answer
    
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. – HEATH3N Jul 12 '15 at 19:52
    
you would need to have the manager prefabbed and drag the prefabbed version into the click event to call. – Justin Markwell Jul 12 '15 at 20:36

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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