Tutorial 2

 Tutorial 2.1

In this tutorial I was tasked with creating a game where the character could fire projectiles at animals. To begin a created a new Unity project which I called Prototype 2. Then downloaded the assets from the unity store. After that I then dragged the 3 animals and the farmer and the piece of food into the hierarchy and adjusted their position and scale accordingly. Then I created a C# script folder in the assets folder, which I named PlayerController and attached the script to the farmer, which I renamed player. I then opened up the script and added a few lines of code. Then I set the speed that the player could travel and allowed him to travel from side to side. Then I made it so that the player had to stay in between a set limit which kept him from leaving the screen. After that I then decide that I should clean up some of the code by first replacing the hardcoded values with a variable called xRange, what this meant was that for whenever a specific value is wanted to be used I can simply say that such a value is equal to xRange and that lets the computer know what I'm asking of it, for example xRange = 10, so if the line of code -xRange shows up I know it means -10. To finish off I added some lines of comments to better make my code more easily understood.

Picture of my work


Tutorial 2.2

In this tutorial I was tasked with making the food be able to move and fly in a straight line. To start I created a new C# script called MoveForword, which I then attached to the food object from the hierarchy. I then wrote a few lines of code so that the food was now able to travel forward, I then tested it out by setting the speed in the inspector. After that I created a new Prefabs folder where I dragged the food into it, afterwards I opened up the PlayerController.cs and made it so that I was now able to drag the food into the scene while it was playing and that it would immediately fly of the screen. Back in the PlayerController.cs I added an if statement, which meant that if specific conditions were met, that a certain outcome would occur, by that I mean if the spacebar was pressed, that a piece of food would be fired and continue of the screen. To finish off my ability to fire a piece of food when the spacebar was pressed, I also had to include an Instantiate method inside of the if statement. Next, I clicked on all of the animals present on the screen and moved them into a more suitable position, I then turned them 180 degrees so that they were facing the farmer. I then changed the speed of the animals, put them in the prefab folder and tested to see if the code that I had previously entered was working by dragging the animals on to the screen. I then needed to have the animals and food be destroyed once they exited the screen, so I wrote down the code to do so and then it worked.

Tutorial 2.3

In this tutorial I was tasked with creating a random stampede of animals that would appear with the touch of a button. To start I created an empty object called SpawnManager in the hierarchy. Then create a new script called SpawnManager and attach to SpawnManager then open it. In SpawnManager I added the code to make an array that matched the number of animals that I had. Next, I added an if statement that allowed me to instantiate a new animal prefab if I pressed S. After testing to see if it worked I soon realised that the only problem with my work was that all of the animals kept on spawning I the same spot, so instead of being a stampede, it was more of a hectic line. So to solve this problem I decide to go back into the SpawnManager.cs and replace some of the values which where already down with the line Random.Range(-20, 20), which basically tells the computer that the animals will spawn on the line anywhere between -20 to 20. Then I had to change the camera perspective so that I could view the animals from a top down view, but also so that they appeared 2D from the top down.

Picture of finished work

Comments

Popular posts from this blog

Game design

Unity Tutorial 02