Join Kelley Hecker for an in-depth discussion in this video Using an event to damage the player, part of Scripting Unity with C#.
- Now, we need to create a function…that responds to the OnDamagePlayerEvent…being sent by the enemy's collider.…If you're starting from the Exercise Files…instead of continuing from the previous video,…remember that you'll need to import…the Standard Assets for Unity 4.6 package…which we imported in Chapter 3…as well as the Stone Frog package…which we did earlier in this chapter.…When the player is hit by the enemy,…their health should decrease.…We can keep track of the player's health…in our GameManager.…Open the GameManager class…and create a new energy property called PlayerHealth.…
I'm going to copy the code from the Exercise Files.…Also add a variable named maxHealth…which is the amount of health the player should start with…and set it to 3.…In Start, we'll set the player's health to the maximum.…We should also reset the player's health…when the game restarts…so in Update, after we reset the time,…set the player's health back to the maxHealth.…
Now, we'll make a function called DecrementPlayerHealth.…This function is going to be called…
- Defining classes and variables
- Attaching scripts to objects
- Understanding MonoBehaviour class
- Using the Unity Scripting API
- Importing assets
- Using a singleton pattern to manage game state
- Creating an event
Skill Level Intermediate
Advanced Unity 3D Game Programmingwith Michael House3h 45m Advanced
Creating Mobile Games with Unitywith Kelley Hecker1h 12m Intermediate
1. Your First Script
3. Built-In Unity Classes
Picking up coins4m 8s
5. Events and Delegates
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.