This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/Scripts/MainMenu/MainMenuManager.cs

66 lines
1.8 KiB
C#

using System.Collections;
using System.Collections.Generic;
using System.Linq;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MainMenuManager : MonoBehaviour
{
private string component = "_FaceDilate";
[SerializeField]
private TMP_Text title;
[SerializeField]
private List<TMP_Text> textList= new List<TMP_Text>();
private List<float> initDilates= new List<float>();
private List<float> dilates= new List<float>();
private float dilate = -1;
private float initDilate;
[SerializeField]
float dilateSpeed = 0.1f;
// Start is called before the first frame update
void Start()
{
//initDilate = title.fontSharedMaterials[0].GetFloat(component);
initDilate = title.fontMaterials[0].GetFloat(component);
foreach(TMP_Text text in this.textList)
{
this.initDilates.Add(text.fontMaterials[0].GetFloat(component));
this.dilates.Add(-1f);
}
this.textList[0].GetComponent<Button>().onClick.AddListener(LoadFirstLevel);
this.textList[2].GetComponent<Button>().onClick.AddListener(ExitApp);
}
void LoadFirstLevel()
{
SceneManager.LoadScene(1);
}
void ExitApp()
{
Application.Quit();
}
// Update is called once per frame
void Update()
{
//dilate = Mathf.Min(initDilate, dilate += Time.deltaTime);
dilate = Mathf.Lerp(dilate, initDilate, Time.deltaTime*dilateSpeed);
title.fontMaterials[0].SetFloat(component, dilate);
for(int i =0;i<this.textList.Count;i++)
{
dilates[i] = Mathf.Lerp(dilates[i], initDilates[i],Time.deltaTime*dilateSpeed);
textList[i].fontMaterials[0].SetFloat(component, dilates[i]);
}
}
}