private void RestartGame() { // Spawn our player character Vector3 playerSpawnPosition = Vector3.zero; Quaternion playerSpawnOrientation = Quaternion.identity; Quaternion playerLookOrientation = Quaternion.identity; if (PlayerSpawnTransform) { playerSpawnPosition = PlayerSpawnTransform.position; playerSpawnOrientation = PlayerSpawnTransform.rotation; } spawnedPlayerCharacter = Instantiate(PlayerCharacterPrefab, playerSpawnPosition, playerSpawnOrientation, GetWorld().transform).GetComponent <LNBPlayerCharacter>(); spawnedPlayerController = spawnedPlayerCharacter.GetComponent <LNBPlayerController>(); // Transform the pitch and not the character #TODO: Write your own player controller playerLookOrientation = spawnedPlayerController.GetComponentInChildren <Camera>().transform.localRotation; spawnedPlayerController.GetComponentInChildren <Camera>().transform.localRotation = playerLookOrientation; // TODO: Async generate our first dungeon // Instantiate our first dungeon currentDungeonInstance = Instantiate(Dungeons[0], Vector3.zero, Quaternion.identity, GetWorld().transform); hubRoomInstance.dungeonController = currentDungeonInstance; currentDungeonInstance.SpawnRoom(hubRoomInstance.exits[0]); }
private int currentHeartIndex = 0; // This is the current heart that we have remaining health in // Use this for initialization void Start() { // Make sure our column and rows are valid if (!heartsColumn) { Debug.LogError("No valid column setup for UI!"); return; } if (!heartsRow) { Debug.LogError("No valid row setup for UI!"); return; } // Look for our player and health components playerOwner = GameManager.GetGameManager().GetPlayerCharacter(); if (!playerOwner) { Debug.LogError("No playerCharacter in world!"); return; } playerHealthComp = playerOwner.GetComponent <Health>(); if (!playerHealthComp) { Debug.LogError("Health UI could not find a health component in the player!"); return; } // Listen for updates from our health component playerHealthComp.OnAddHealth.AddListener((float amt, bool refill) => { OnHealthAdded(amt); }); // Ignore refill because we'll listen for it on the OnHeal event playerHealthComp.OnSubtractHeath.AddListener((float amt) => { OnHealthRemoved(amt); }); playerHealthComp.OnTakeDamage.AddListener((GameObject attacker, float amt) => { OnHealthChanged(amt, true); }); // For these two listeners we only care about the change in amount playerHealthComp.OnHeal.AddListener((float amt) => { OnHealthChanged(amt, false); }); if (!heartPrefab) { Debug.LogError("No heart prefab set!"); return; } // Create our heart list and add our prefab heartList = new List <HeartUI>(); heartList.Add(heartPrefab); // Figure out how many hearts we need to add OnHealthAdded(playerHealthComp.GetMaxHealth - 100); // We subtract a hundred from the current amount accounting for the first heart we added }