Interactivity : Customising my Game

/
0 Comments
Idea

I'm bringing back my potato famine video from one of last year's small exercises and turning elements from it into the game! It is based off the ending of the video in which it shows potatoes raining from the sky in reference to Ireland having all the potatoes no problem again. The player will be the farmer and the aim is to catch the potatoes falling from the sky and eat them. If the player fails to eat a potato and it goes past the boundary of the game, the game will be over and the player will have to restart. 

Video from last year

Making and adding the models/ background for my game

I took a screenshot from the video and then removed the background and any unwanted material using the Quick Selection Tool. This was then saved to the texture folder, inside my Unity Folder, ready for access in the software.

Image with no background

I had previously sculpted potatoes in Sculptris and textured them in Maya, specifically for my game. I saved these from Maya into the Models folder inside the Unity Assets Folder on my Desktop so that they would appear in the folder when Unity was started. 

Saving the potatoes in Maya

Potatoes in Models folder in the Assets folder in Unity

For the background I looked for fields on google images and chose my favourite. I then saved this into the Texture folder inside Assets, similarly to the image of the farmer.

Field texture in folder

The field and farmer textures in Unity

To change the background from the space one previously used in lesson I selected the Background object in the Hierarchy. In the Inspector, I chose where it says 'Select' which brought up a select texture window. I chose the field image that I had placed in the folder earlier. Then I changed the Shader in the Inspectir to 'Unlit/ Transparent' so that no light would effect the background. 

Select Texture Window for Background

Shader selected as 'Unlit/ Transparent' with new texture appearing in the select box

Final texture on background 

To add the texture of the farmer and allow it to work in the same way as the spaceship used in lesson, I created Quad game object in the Hierarchy. Next I used the position tool to move the Quad over the top of the spaceship. With the Quad selected, I used the same technique as adding the background to place the farmer texture on the game object. I went to the select box and chose the farmer texture and made sure the shader was set to 'Unlit / Transparent.' I then parented the Quad to the Player in the Hierarchy. Finally, as the spaceship could still be seen underneath the farmer texture, I disabled the 'Mesh Renderer' to make this invisible. The result was that the spaceship had seemingly been replaced by the farmer. 

Quad added to Hierarchy


Quad positioned over spaceship

Texture added to Quad

Quad parented to player

Spaceship still visible under Quad

Disabling Mesh renderer

Spaceship now invisible - replaced with new texture

Adding Sound Effects and Music and Destroying the Player at Game Over

I downloaded my selected sound effects and music and added them to the Audio folder in Assets to be accessed in Unity. To add the background music I selected the GameController in the Hierarchy and the went to the Inspector to change the Audio Source from the previous music to my new potato song. Once that had been added, I made sure that Play On Awake and Loop were selected in the Audio Source, to make sure the music would play as soon as the game was started and also to ensure that the music would continue throughout the entire time the game was played. 

Adding tracks to Audio folder


Select Audio Window - potato song selected

Completed Audio Source tab - new audio added, play on awake and loop selected

To add the sound effects I had to add various pieces of code to my already made scripts from lesson. I began by adding a 'Nom' sound effect every time the player came in contact with the potato, showing that the potato has been eaten. To do this I went to the DestroyByContact script and replaced some of the coding associated with the asteroid with the following :



'gameScript.AddScore (scoreValue);' allowed the score at the top left of the game to be updated by 10 points every time the potato came in contact with the player (the farmer). I added an Instantiate function in order make the nom sound play every time the potato comes in contact with the player. The Destroy function meant that as soon as the potato came in contact with the player it would be destroyed and disappear, giving the appearance of being eaten. 

Finished DestroyByContactScript

To add the 'Wawawa' sound effect when the game was over to show the player has lost, I had to activate it when the first potato reached the boundary just off of the Game View scene. To do this I added more code to the GameController script. 



In the 'public void GameOver()' section of the script I added to the 'If' statement an 'Instantiate.' This means that as soon as the game is over, and the Game Over text is activated due to the potato hitting the boundary, the sound effect will be played. 'GetComponent<AudioSource>().Stop();' was added in order to make the background music stop as soon as the game was over, in order to focus on the 'Wawawa' sound effect. A 'Destroy' was also added to make the player disappear when the game was over, so as they cannot continue to collect the remaining potatoes falling before restarting. 

To make these work in the game, I selected GameController in the Hierarchy. In the Inspector under 'Game Controller (script)' I dragged the 'Wawawa' prefab from the Assets folder on to the 'Wawawa Pre Fab' in the Inspector, in order to link it. 

Prefabs folder

Wawawa sound linked on Wawawa Pre Fab

For the 'Nom' sound I selected the potato prefab in the Assets folder. In the Inspector, under the 'Destroy By Contact (script)' section I selected the Nom sound from the Audio folder and linked it to the Nom Pre Fab. 

Nom sound linked to Nom Pre Fab

The result was that every time a potato hit the farmer the sound would be activated. When the game was over, the 'Wawawa' sound effect would be activated and the music would stop. 

Adding and Scripting the Potatoes Falling
To add the potatoes to the game I went to the Prefabs folder in Assets and dragged the Asteroid prefab from lesson into the Hierarchy. The in the drop down menu I selected the model . In the Inspector I clicked the circle on the right hand side of the Mesh option. This allowed me to change the mesh object - I personally changed this to one of the potatoes. The result was that the asteroid was replaced by a potato. 

Asteroid in Prefabs folder

Asteroid dragged to Hierarchy - Model selected in drop down menu

Original Mesh of asteroid

Potato mesh selected to be changed to

Potato now in game instead of asteroid

To make the potatoes spawn like the asteroids I selected GameController in the Hierarchy. In the Inspector under 'GameController (script)' I changed the asteroid prefab with the newly created potato one. This meant the asteroids were replaced with potatoes. 

Removing Rotation of Player

As now the player is not a spaceship and therefore when turning left and right does not rotate in a vehicle motion, i decided to get rid of the rotation on the 'ship.' To do this I went to the C# script and chose the following piece of code :


This was then deleted to completely remove any rotation on the farmer. The result was that the player would move solidly left and right instead of turning around. 

Removing the Bolt

The aim of the game is to eat the potatoes, not to destroy them with a bullet like the spaceship does with the asteroids. Therefore the bolt was not needed anymore. To remove the bolt I went to the PlayerController script, selected the following section of coding (that codes for the bolt being fired) and deleted it. This meant that when the mouse was clicked no bolts would be fired. 

Piece of code deleted to remove bolt

Adding a High Score

To add a high score to the game the following pieces of coding were added to the GameController script :



In the 'Void UpdateScore()' section I added an 'If' statement. This was saying that if the score is bigger than the high score, then the high score will equal the score. The 'highScoreText.text' part allows the High Score to then be updated to this new higher total. 

Final GameController script

Game with high score now added






You may also like

No comments: