Pages

Thursday, 29 November 2012

Main Menu Code


Since writing my last blog post I have been working on the AI and the menu code within our dissertation game as well as another one for this module.

I have been able to get the menu codes working to a level that I am happy with. This is a really helpful piece of code as it allows me to be able to use it across multiple games that I am undertaking on this course.

The basics of it are that when the user is presented with a menu screen, they can click on the play button and be taken straight into the game. Also, if they click on the Quit button, it will quit the application for them. This code will also work for taking the player to an options screen as well as any other screens we decide to implement on the main menu.

I completed this work using the code C#. Unfortunately, I was unable to use my preferred coding method, which is playmaker. This was due to a lack of tutorials that I could find on the subject.

The process of getting the menu buttons to work is quite simple once trail and error has been used. First an empty game object is brought into the Unity scene; next it is resized and shaped to form the play button on the menu. The code is then written and then dragged and dropped onto the button.

It was decided that each level and screen would be in a different scene. This is to make the game less demanding on the machine it is running off. Because of this, each scene that we make must be named correctly in the build settings for the menu code to work. The code is below:

var isQuitBtn = false;

function OnMouseUp()
{
     if(isQuitBtn)
     {
          Application.Quit();
     }
     else
     {
          Application.LoadLevel(1);
     }
}

To summarise this code, it works by sending a message to the scene where when the mouse button is clicked and released, the game will either quit or play depending on which button the player has targeted. The number in brackets after ‘Application.LoadLevel’ relates to level that is started upon the play button being selected. This may look very simple, but as I am still new to coding, this was very pleasing to complete. What is even more rewarding was seeing it work and understanding the processes behind it.

Next, I plan on using the knowledge I have learned whilst working on the AI, to create routes within the game that the enemy can navigate. I hope to progress on this work over the weekend so that next week Tom and myself can start planning out the first level design.

Written by Phil

No comments:

Post a Comment