So i have 2 different scenes. One is the MainScene with MainMenu Panel, LevelSelection Panel, Settings Panel and Shop Panel. Other is the Level1 Scene. So on the Level1 scene i have a progress bar and coin reward for each finished level. On MainScene, LevelSelection Panel there is also a progress bar for each level and a global coin counter. How can i connect progress bars and coin systems from two scenes, so that when Level1 is finished, 5 coins are added on the LevelSelection Panel and progress bar also "progresses" for 1? Here is my script for the progress bar, i haven't made the coin one yet, but i have an idea for that too:
PROGRESS BAR:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ProgressBar : MonoBehaviour
{
[SerializeField]
private Image stars;
[SerializeField]
private Image stars_full;
private int level = 0;
private float currentAmount = 0;
private Coroutine routine;
private void Awake()
{
DontDestroyOnLoad(gameObject);
}
public void OnEnable()
{
level = 0;
currentAmount = 0;
stars_full.fillAmount = currentAmount;
UpdateLevel(level);
}
public void UpdateProgress(float amount, float duration = 0.1f)
{
if (routine != null)
StopCoroutine(routine);
float target = currentAmount + amount;
routine = StartCoroutine(FillRoutine(target, duration));
}
public IEnumerator FillRoutine(float target, float duration)
{
float time = 0;
float tempAmount = currentAmount;
float diff = target - tempAmount;
currentAmount = target;
while (time < duration)
{
time += Time.deltaTime;
float percent = time / duration;
stars_full.fillAmount = tempAmount + diff * percent;
yield return null;
}
if (currentAmount >= 1)
LevelUp();
}
public void LevelUp()
{
UpdateLevel(level + 1);
UpdateProgress(-1f, 0.2f);
}
public void UpdateLevel(int level)
{
this.level = level;
}
}
And in my Level1 Control script i just call the UpdateProgress() method and it works. Also can i somehow stop the progress bar reseting when Level2 is loaded with DontDestroyOnLoad()?