//written by Aiden Harrington and Connor Blondin-Beale //Placed on level settings on main level class PlayerHud : ZilchComponent { [Property] var HudLevel: Level; var HudSpace: Space; //HealthText is the SpriteText that I used to show the health of the player //this can be given any name you chose and update it through the script //for this code to work the sprite text you are updating must be give THE SAME NAME as this variable var HealthText : Cog; //Name given to the variable that stores the user controlled player information var PlayerSprite : Cog; function Initialize(init : CogInitializer) { Zero.Connect(this.Space, Events.LogicUpdate, this.OnLogicUpdate); this.HudSpace = this.GameSession.CreateNamedSpace("HudSpace", Archetype.Find("Space")); this.HudSpace.LoadLevel(this.HudLevel); //stores the user controlled player information so that we can quickly find it //without exhausting resources this.PlayerSprite = this.Space.FindFirstObjectByName("Player"); if(this.HealthText == null) { this.HealthText = this.HudSpace.FindObjectByName("HealthText"); } } function OnLogicUpdate(event : UpdateEvent) { //this the main part of the script, it updates the hud to display the player's health //This can be used to display anything such as coins, score or ammo this.HealthText.SpriteText.Text = "`this.PlayerSprite.PlayerHealth.HealthPlayer`"; } }