SHADE_Y3/Assets/Scripts/UI/SC_ChangeSceneButton.cs

48 lines
968 B
C#

using System;
using System.Reflection.Metadata.Ecma335;
using SHADE;
using SHADE_Scripting.UI;
public class ChangeSceneButton : Script
{
public uint sceneID = 0;
public GameObject levelTransistion;
private bool clickedFlag;
protected override void awake()
{
clickedFlag = false;
}
protected override void start()
{
UIElement ui = GetComponent<UIElement>();
if (ui != null)
{
ui.OnRelease.RegisterAction(() =>
{
if (sceneID != 0)
{
Audio.PlaySFXOnce2D("event:/UI/success");
Audio.StopAllSounds();
clickedFlag = true;
levelTransistion.SetActive(true);
}
});
}
else
{
Debug.LogError("Failed to register button action for ChangeSceneButton.");
}
}
protected override void update()
{
if (levelTransistion.GetScript<LevelTransistion>().complete && clickedFlag)
{
SceneManager.ChangeScene(sceneID);
}
}
}