Posts

Showing posts from April, 2018

Unity Project 6: Coin Collection (Code Explained)

Image
This is the script used to control the health bar.  When damage is taken the health is decreased. Health bar script This script creates the floating effect that is on the coin by transforming the values on the y-axis by using a Sin wave from its original position. Idle Move script This script allows the player to pick up the coin.  Each coin is assigned to a tag named "Player" and therefore whenever the player collides with any object assigned to this tag the particle system is played creating a particle explosion and the object (coin) is 'disabled' causing it to disappear as the particle system is played.  The inner and outer mesh are destroyed on collision. Pick up script When the player collides with the object, the health bar decreases by 10. The != operation returns false if its operands are equal, true otherwise. Spike Trap script This script allows the object (coin) to constantly rotate, the speed is defined in ...

Unity Project 6: Health Bar

Image
Scene view When the player collides with the spike trap, their health is decreased by 10. Gameplay The max health and health is defined.  When the player collides with the spike trap the health bar's foreground (Red colour) is decreased by 10. Health bar inspector

Unity Project 6: Particles

Image
Particle system acting on the coin Setting the values for the particle system allowed us to cause an explosion type effect with the coin when collected by the player. Looping was unchecked so that the particle system was only activated when triggered by the player. Other elements were also changed such as the colour of the particles so that they matched the colour of the coin. Particle system gameobject

Unity Project 6: Coin Collection

Image
Standard assets imported from the asset store so that we could use an FPS controller. Standard assets Coin Gameplay Scene view Invisible enemy (Spike)  'Spike Trap' script attached so that when the player collides with the spike trap, an object can be triggered or an event can occur (such as. losing health). Enemy Inspector The 'Pick Up' script is attached to the coin object. Coin Inspector Outer mesh of the coin has an 'Idle Move' and 'Constant Rotation' script attached, allowing the coin to move up and down on the spot as a type of animation. Outer Mesh of Coin Inspector Assets Hierarchy

Unity Project 5: Opening Doors (Code Explained)

Image
This script opens and closes the door panel by setting the boolean value in the animator panel to true or false depending on whether the conditions fit whether the door needs to be open or closed. If the conditions for either are met, either the open or closed animation for the door is played in the game. DoorOpenClosed script This script works based on whether the player has collided with the door or not. If the player has the door open animation is triggered, if they have not the door continues to be closed or the door close animation is triggered by setting the boolean value to either true or false. DoorOpenForPlayer script

Unity Project 5: Opening Doors

Image
Scene view Animator panel, where you can create a motion path for the door to open and close. Animator panel Connected nodes which tell you whether the door is open or closed based on a boolean decision. Door is open Door is closed Gameobject with an animator component, that allows the door panel to be animated and has the 'DoorOpenForPlayer' script which opens the door when the player is in close proximity to the door. Door frame inspector When the player is in close proximity to the door, the door opens. Door opened Door closed, as the player is too far away from the door for it to be open. Door closed Hierarchy Parameter 'IsOpen' (Boolean) is unchecked so that the door begins closed as it isn't open otherwise the door would be open. Parameters The 'Loop Time' box needs to be unchecked on the animated asset otherwise the door will continuously open and close. This looping isn't needed as...

Unity Project 4: Ball platformer game (Code Explained)

Image
'RollingBall' script allows the ball to be moved by the player using the 'W, A, S, D' keys. When any of these buttons are pressed then the ball will move in the direction that has been set in the code. When the space key is pressed, the ball jumps and again uses force of the object's Rigidbody. Moreover, the script adds force to the Rigidbody of the object making the ball a little bit more difficult to control. The value can be edited in the scene view. RollingBall script The script rotates the two cubes which look like a windmill. Transform.Rotate allows the arms to rotate around the same axis. The speed is set in the scene for the windmill. RotatingWindmill script When the ball collides with whatever object this script is attached to (invisible cube) then the word 'COLLIDED' is printed in the console. This trigger can be used for many different aspects in a game. This may include: spawning enemies, losing/gaining health, acti...

Unity Project 4: Ball platformer game

Image
Finished game displayed in the scene view. Scene view Assets Uses Rigidbody so that the ball can use physics (Gravity) therefore it doesn't fall through the ground. The 'Rolling Ball' script is attached to the ball which adds force to the ball. Ball Inspector Scene view displaying the invisible cube object which can be used as a trigger for an event. Scene view When the console prints 'COLLIDED', the ball has collided with a specific object (Invisible cube). Console Message The invisible cube that is attached to the 'Trigger' script. When an object does not have a mesh renderer, the object becomes invisible as we cannot see it due to it not having a mesh. Cube Inspector Field of view changed, so that the ball can be seen from a slightly different angle. Follow target script also attached allowing a first person type view of the ball as the camera is set to follow the ball's movement. The camera can be moved so tha...

Unity Project 3: Beer Pong Code Explained

Image
This script has been written with the purpose that when any gameobject with the tag "Cups" has collided with the ball gameobject, they are destroyed (they disappear). The 'Rotation' script allows the cannon to rotate making the game more difficult.  The script generates balls to shoot from the cannon when a key (Space is pressed).

Unity Project 3: Beer Pong

Image
I really liked this exercise as it was interesting and the game was fun to make. By pressing the space button a ball clone would fire out of the cannon hitting or missing the cups. The aim of this game was to fire the cannon so that the ball would land in the cups. Ball Pong Scene Game Play Scene Asset list Hierarchy Ball Inspector Cannon Inspector