Skip to content

Commit

Permalink
Fix GameManager current level number
Browse files Browse the repository at this point in the history
  • Loading branch information
arifemrebulut committed Sep 22, 2022
1 parent 3fb4528 commit cd6af28
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Assets/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

public class GameManager : MonoBehaviour
{
public int CurrentLevelIndex { get; private set; }
public int CurrentLevelIndex { get; private set; } = 0;
public GameStatus CurrentGameStatus { get; set; }

public static GameManager Instance;
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/PlayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,4 @@ private void PunchScaleOnStop(Vector3 direction)
transform.DOPunchScale(new Vector3(punchScale.x, punchScale.y, -punchScale.z), punchScaleDuration, punchScaleVibrato, punchScaleElasticity);
}
}
}
}
20 changes: 12 additions & 8 deletions Assets/Scripts/UISystem/GameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,22 @@ public class GameUI : MonoBehaviour, IUIController

[SerializeField] private TextMeshProUGUI levelText;

private void OnEnable()
private int levelIndex;

private void Start()
{
EventManager.LevelSuccesEvent += UpdateLevelText;
levelIndex = (GameManager.Instance.CurrentLevelIndex + 1);
levelText.text = "LEVEL " + levelIndex.ToString();
}

private void OnDisable()
private void OnEnable()
{
EventManager.LevelSuccesEvent -= UpdateLevelText;
EventManager.LevelSuccesEvent += IncreaseLevelNumber;
}

private void Start()
private void OnDisable()
{
UpdateLevelText();
EventManager.LevelSuccesEvent -= IncreaseLevelNumber;
}

public void Close()
Expand All @@ -32,8 +35,9 @@ public void Open()
gameObject.SetActive(true);
}

private void UpdateLevelText()
private void IncreaseLevelNumber()
{
levelText.text = "LEVEL " + (GameManager.Instance.CurrentLevelIndex + 1).ToString();
levelIndex++;
levelText.text = "LEVEL " + levelIndex.ToString();
}
}

0 comments on commit cd6af28

Please sign in to comment.