Unity Tutorial 06


Image from the tutorial

For this weeks Unity tutorial I had to continue on from last weeks one. This week I had to learn how to make the player going from a running state when using the running controls, a jumping state when using the jump controls and a death state when the player hit a barrier. To do this I had to use an animation controller. 


Animation controller

The animation controller is what is used to control the players animations which is pretty self explanatory. The animation controller controlled each state that the player is in so I needed to use it to get him into any one of these three states when needed. When I clicked on walk or run the players animation character walked or ran however when I clicked walk_static or run_static the animation character only ran or walked on the spot. I then had to edit the players condition. I had to change the speed from 0 in order to get him to move. I then had to make the player start off by running. To do this I had to go to the parameters tab and set his speed variable to 1.0 and set run_static as his default state and set the speed value to 1.5 in the inspector to match the speed of the background. Although I had the player in a running state when he jumped over obstacles he was still in a running state rather than a jumping state so I had to fix this using the PlayerController script. I had to create a private animator called playerAnim; I then had to go into the Start method and create a new animator component. I then had to use the If-Statement and add playerAnim.SetTrigger("Jump_trig"). I then had to set my players speed to 0.5 so that he could run and jump for longer. I then had to set the players mass to 60, his jump force to 700 and his gravity modifier to 1.5 to make the jump just right. After this I had to move onto the dying state. To do this I had to add four new conditions to my animation controller called death_01, death_02, dead_01 and dead_02. I had to set the death bool to true and set the death type integer to 1. I then had to go to the gameOver section in my PlayerController script and go down to the If-Statement and add in playerAnim.SetBool("Death_b" , true);  I then had to add in playerAnim.SetInteger(DeathType_int", 1); My player then went into the dead state whenever he ran into the obstacle however he was still able to jump whenever the spacebar was pressed so I needed to fix this. To do this I had to go into my If-Statement in my Update method and add in if (Input.GetKeyDown(KeyCode.Space) && isOnGround && !gameOver). After this I then had to add in sound effects and particles. I had to make an explosion happen whenever the player ran into the obstacle. To do this I had to go into my course library and go into particles and bring FX_Explosion_Smoke into my hierarchy and add the particle to my player. I then had to go into my PlayerController script and create a new public ParticleSystem called explosionParticle; I then had to go into my If-Statement and add in explosionParticle.Play(); I then had to bring the FX_Explosion_Smoke into my PlayerController script. I then had to add a dirt splatter effect onto my player to make it look like the player is kicking up ground as they are running. I then had to make a new public ParticleSystem called dirtParticle; and then I had to go to my gameOver section and add in dirtParticle.Stop(); Then I had to go to my collision If-Statement and add in dirtParticle.Play(); and dirtParticle.Stop(); This was to make sure no dirt came from my players shoe when he was jumping or on the ground. I then had to move onto the music. To do this I had to go to my main camera and add in an audio source component. I then had to choose a sound from the sound folder and then drag a music clip to my Audioclip in the inspector and then tick the loopbox so the music played the whole time my character was running. I then had to create variables for my audio clips. To do this I had to go into my PlayerController script and create a public Audioclip called jumpSound; and another one called crashSound; I then had to drag a clip onto each sound in the inspector. I then had to play audio clips whenever my player jumped or crashed into the obstacle. To do this I had to create a private AudioSource called playerAudio; I then had to go to my Start method and add in playerAudio = GetComponent<AudioSource>(); I then had to add playerAudio.PlayOneShot(jumpSound, 1.0f); to my Update method so that it makes a sound when the character jumps and add playerAudio.PlayOneShot(crashSound, 1.0f); to my Void method so that it makes a sound when my player crashes into the obstacle.  I then had to add an audio source component to my player. I learned how to give my player a running state, a jumping state and a death state, how to add explosions to my player and add music and sound effects to my game. 



 

Comments

Popular posts from this blog

Introduction Post

My Favourite Game: Grand Theft Auto Franchise

Game Alpha