2D - Making a menu appear

Working on a 2D strategy game. I have my map, my player character, and the menu of commands that will appear when you click on them. Problem: I can’t find the code that will allow the menu to show up. Google helped me get as far as:

function OnMouseDown ()
{

}

…but I can’t figure out what’s supposed to go in-between those brackets. The asset itself is called “ProtoMenu”, if that helps. And yes, my character asset has a 2D Box Collider and a RigidBody. Not sure if I need those or not for what I’m doing, but they’re there. The goal of this is that eventually I’ll be using this menu to help the player move and select units to attack, so hopefully I’m on the right track so far.

Start thinking with GameObjects. GameObject is the name of the class describing everything a GameObject can be, but an individual object is referred to as a gameObject.

An individual gameObject is composed of Components. These are the fields you see in the inspector; such as your Box Collider and Rigidbody.

It sounds like you want to make a gameObject appear in the world. First, you need to make that object. Place your asset into the Scene Editor, and attach all the Components that will make your gameObject function (one of them will probably be a script to give it some behavior).

Go ahead and get your object working, however it does.

Now in the Project pane create a folder called Prefabs. In it create a new Prefab. simply drag the asset from the scene onto your Prefab. Now any time you drag your Prefab into the Scene Editor, it recreates all the settings and Components you gave it! If you select an instance of your Prefab, the top of the inspector will show assign and revert buttons. They assign changes made to the instance to the Prefab or revert changes to those of the Prefab!

From here, you will use the Instantiate function. You will tell it what Prefab to make appear by name, where you would like it to appear, and its rotation.

In my current project, instantiating a new Fly prefab is as simple as:

        if(Input.GetButtonDown("Space"))
        {
            Instantiate(aFly);
        }

But in the future, conditional logic will control when and where to create flies.

That’s all true, however, I think it may be overthinking the menu a bit.

You shouldn’t need to instantiate the menu; it should already be there in your scene, just deactivated. To make it appear, you only need to activate it with SetActive(true). Since these are menus related to the object you click on, you might also want to move it to the screen position of the object clicked, but that’s step 2; worry about step 1 first. :slight_smile:

Of course I don’t know if ProtoMenu is set up differently than I imagine. I think you should look in the ProtoMenu docs or sample code — surely they have an example in there that shows you the intended way to show the menu?