2D game creation workflow general questions

Hi there,
I’ve just discovered Unity and I wanted to give it a try by developing my first game ever (I’m an engineer with a good programming background but I never had enough time to make a game :smile:).

I’ve learned C# by developing apps for Windows Phone, and this gave me some concepts on how MVVM works and stuff like that.
Since Unity supports C#, I thought that I would have been able to make a game without problems, by using what I learnt during my WP experience.

Now, after some days of tests, I’m afraid that I was wrong.

I’m finding it hard to understand how to make some scripts “communicate” and share data, how to access to some specific class instance and stuff like that.

So I’m asking for your help with a few questions.

Provided that I already have a clear idea on how my game should work, what’s the correct workflow to get from the idea to the actual game (including advertising, social capabilities and everything needed to make a “professional” app)?

What’s the best practice to separate the roles for my classes?

How can I build a game manager class that interacts with the elements on the scene and reacts to what happens after user’s input?

I know that the questions may seem odd, that’s why I’m adding a quick sample:

Let’s say that I’ve got a GUI with a button and a label in which I print the number of times that the button got hit.
From my previous experiences, I know that the button should just say “hey, I’ve been clicked!” without doing anything else and the game manager class should intercept this “event” and add one to the click’s count.
The same game manager should also disable the button once we reach 10 clicks.

In MVVM I’d just work out with the “IsEnabled” property, but now I don’t even know if I can access that button because everything stays on a separate GameComponent and it seems that a GameComponent doesn’t know the other components.

It’s just …a big mess!

Can someone help me sorting out this thing and having a clear vision on how to make a 2D game in Unity?

Thanks :slight_smile:

As far as accessing scripts, allowing scripts to talk to one another, you have 3 methods at hand. (Maybe there are more, but I know 3). So, what are they???

If you know, pre game run, the scripts and objects that will need to talk… In your case you mentioned a GUI with a button, the buuptton must register each time it is clicked them shut of when clicked ten times. This could be handled by one script on the button itself, but for arguments sake, let’s say you want to have it pass all information to a separate script, a manager.

I would have two scripts in this case, one, btnScript and two, mngScript.

///in btnScript
void btnPressed(){
///here we need to access the mng, to tell that this btn was pressed
}

So, since we know that this btn needs to talk to its mng…
Unity, C# allows for you to use a scripts name as a Class, variable, another script can use to access it.

///btnScript

public mngScript mng;
///assign in the inspector, before run.


void btnPressed(){
mng.theGUIBtnWasPressed();
}

I know I this step is irrelevant but I am simply illustrating how to communicate between scripts as asked…

now, in the mngScript…

public void theGUIBtnWasPressed(){
///do stuff here
}

That above method is preffered for talking between scripts as it is easier on the engine then using your other two option for communicating between scripts, GetComponent and SendMessage.

I hope that helps.

Do I have to put both scripts into the same objects?

Because I’m trying it with two scripts associated to 2 different objects, and is throws a NullPointerException…

You can, but are not required.

If there is a null pointer it means you are not assigning something.

Well, if I’m not wrong

    ///btnScript
     
    public mngScript mng;
    ///assign in the inspector, before run.
     
     
    void btnPressed(){
    mng.theGUIBtnWasPressed();
    }

will always throw a NPE as the var mng is won’t be initialized…