private void UpdateHealthBarPosition(HealthBarViewMediator healthBar, GameObject character) { Vector3 characterPosition = character.transform.position; characterPosition.y += 3.5f; RectTransform healthBarRect = healthBar.GetComponent <RectTransform>(); Vector2 screenPosition = RectTransformUtility.WorldToScreenPoint(Camera.main, characterPosition); healthBarRect.anchoredPosition = screenPosition; }
private void CreatePlayerHealthBars() { foreach (PlayerType playerType in _playerControllers.Keys) { GameObject playerObject = _gameViewContext.GetPlayerView(playerType).PanelHierarchy.character.gameObject; HealthBarViewMediator healthBar = GameObject.Instantiate(_gameViewContext.HealthPanel, _gameViewContext.HealthContainer.transform); GetPlayerController(playerType).HealthBar = healthBar; _healthBarToPlayerCharacters.Add(healthBar, playerObject); } UpdateHealthBarsPositions(); }