Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using System.Collections;
- public class LevelSystem : MonoBehaviour {
- [SerializeField] int[] levelPoints;
- [SerializeField] Color backgroundAtStart;
- [SerializeField] Color[] backgrounds;
- [SerializeField] float colorChangingTime;
- public static int level;
- float point;
- public delegate void LevelPass();
- public static event LevelPass OnLevelPass;
- void Start(){
- Camera.main.backgroundColor = backgroundAtStart;
- }
- void Update(){
- point = PlayerPrefs.GetInt("Point");
- SetOnLevelPass();
- }
- void ChangeColor(){
- StartCoroutine("ColorChanger");
- }
- IEnumerator ColorChanger(){
- float ElapsedTime = 0.0f;
- float TotalTime = colorChangingTime;
- var camera = Camera.main;
- Color current = Camera.main.backgroundColor;
- Color next = backgrounds[level - 1];
- while(ElapsedTime < TotalTime)
- {
- ElapsedTime += Time.deltaTime;
- camera.backgroundColor = Color.Lerp(current, next, (ElapsedTime / TotalTime));
- yield return new WaitForEndOfFrame();
- }
- ElapsedTime = 0;
- yield return null;
- }
- void SetOnLevelPass(){
- for(int i = 0; i < levelPoints.Length; i++)
- {
- if(point == levelPoints[i])
- {
- level = i + 1;
- OnLevelPass();
- }
- }
- }
- void CallLevelPassedOnce(){
- PlayerPrefs.SetInt("Point", PlayerPrefs.GetInt("Point") + 10);
- }
- void OnEnable(){
- OnLevelPass = null;
- OnLevelPass += CallLevelPassedOnce;
- OnLevelPass += ChangeColor;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment