Script for Enemy Sprite:
Script for Game Manager:
In the above script, the Enemy Sprite sends the "Enemy Hit" message to the Game Manager if it hits by the Ball Sprite (bullet). Upon receiving the "Enemy Hit" message, the Game Manager will add the score with 10.
In Unity, we are going to do the same. Text containing the score value will look like as following picture.
Script for Enemy sprite:
Script for Game Manager:
Just like in Scratch, in Unity, the Enemy sprite shall also send the "EnemyHit" message to the Game Manager. Upon receiving that message, the function whose name is the same as the message name which is the "Enemy Hit" will be executed by the Game Manager. In that function, the score variable will be added with value 10 and also the Text UI will be updated to the latest score value. Text UI (User Interface) is a Unity object that can display text on the screen. Since we are going to use Text UI in our code, don not forget to write the command using UnityEngine.UI; at the top of the script.
Before we run the program, in Unity we shall first create the Text UI that will contain the score text just like the following picture.
Below is the tutorial video on how to create Text UI for the score.
Below picture give detailed explanation on command that updates the Score Text UI.
Assignment 4
Update the program so that the score will be increased by 5 if the enemy that move from top to bottom (see assignment-3) is hit by the Ball Sprite.
Tidak ada komentar:
Posting Komentar