Unity Tutorial 03 (Semester 2)

(Image of enemy from the tutorial)

For this weeks Unity tutorial I continued on with my Ruby's Adventure tutorials that I have been doing since the beginning of the semester. At this point I had my world set up but this week I had to make it possible for Ruby to collect items such as health packs. First off I had to give Ruby some health. To do this I had to add a health variable to my script. After this I had to add a new variable called a function in order to change my characters health. I had to add the following code: void ChangeHealth(int amount), currentHealth = Mathf.Clamp(currentHealth + amount, 0, maxHealth); Debug.Log(currentHealth + "/" + maxHealth); After I did this I was able to see Ruby's health in the console window. I then had to make it possible for Ruby to collect health. To do this I had to find the CollectibleHealth object in my assets folder and add it to my scene. I then had to adjust the PPU value to the right size. I then had to add a box collider to my GameObject and resize so it would fit better. I then had to tick the is trigger box in my inspector. I then had to create a new script called HealthCollectible and add it to my GameObject and delete my start and update methods and add the following code: void OnTriggerEnter2D(Collider2D other) and Debug.Log("Object that entered the trigger" : " + other); I then had to add a property to my RubyController script and HealthCollectible script. I had to add an if statement to my HealthCollectible script called if(controller.health < controller.maxHealth). After I finished this tutorial I had given Ruby health and I had made health packs collectible. Next up I had to create damage zones for my character as well as enemies. First I had to reset Rubys health to maxhealth instead of 1 because then you would lose the game instantly. I then had to create a new GameObject from the damageable sprite and add a box collider to my damageable GameObject as well as an is trigger component. I then had to create a new script called DamageZone and add it to my damageable GameObject. I then had to resize my damage zone using the sprite renderer. To do this I had to set my GameObject to 1,1,1 in my transform component. I then had to change the draw mode to tiled and the tile mode to adaptive. I then added in my enemies by downloading the image above and adding it to my scene. I then had to give my enemy a Rigidbody and a box collider. I then had to set my gravity to 0 on the enemy like I did with Ruby. I then had to create an EnemyController script in order to get my enemy to move. I already knew how to get my enemy to move as I have done this so many times before using Unity so the code wasn't new to me. I then had to make it possible for my enemy to take damage using the OnCollisionEnter code that I am used to using.

 

Comments

Popular posts from this blog

Introduction Post

My Favourite Game: Grand Theft Auto Franchise

Game Alpha