Mastering Unity 2017 Game Development with C# by Alan Thorn

Mastering Unity 2017 Game Development with C# by Alan Thorn

Author:Alan Thorn
Language: eng
Format: epub, mobi
Tags: COM012040 - COMPUTERS / Programming / Games, COM051310 - COMPUTERS / Programming Languages / C#, COM060080 - COMPUTERS / Web / General
Publisher: Packt
Published: 2018-09-03T10:24:04+00:00


The Typer script should be attached to the root Typer object, and that's it! We now have a class that can type text, throwing it inward into the scene, ready to whack a zombie:

Testing the Typer class

Health and damage

Next up, we consider health and damage. Health is an interesting property, especially because it is abstract, that is, many characters have health: the player character and enemies, including the zombies. Though zombies are neither alive nor dead, but are undead, they still normally have an equivalent metric corresponding to health. When that property or resource is exhausted for any character, they expire, die, or are removed from the game. Due to the generic quality of health, it's a good idea to code it once so that it can be applied limitlessly as a component to any entity that has that property. For this reason, we'll create a Health class. Consider the following full source code and the comments that follow it:

//------------------------------------ using UnityEngine; using System.Collections; using UnityEngine.EventSystems; using UnityEngine.Events; //------------------------------------ public class Health : MonoBehaviour { //------------------------------------ public float Value { get{return fValue;} set { fValue = value; OnHealthChanged.Invoke(); if (fValue <= 0f) OnHealthExpired.Invoke(); } } [SerializeField] [Range(0f,100f)] private float fValue = 100f; //------------------------------------ //Events called on health change public UnityEvent OnHealthExpired; public UnityEvent OnHealthChanged; //------------------------------------ }



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.