Switch
Workflow
Basically, you can think of this thing as a re-skinned toggle.
Saving Data
You can save the switch value by enabling the ‘Save Value’ option. Note that each switch must have its own unique ‘Save Key’ value. Otherwise, there may be conflict(s) between the switches.
Scripting
using UnityEngine;
using Michsky.UI.Hex; // Namespace
public class SampleClass : MonoBehaviour
{
[SerializeField] private SwitchManager mySwitch;
void Start()
{
// Set new value
mySwitch.SetOff();
mySwitch.SetOn();
// Change settings
mySwitch.isInteractable = false;
mySwitch.useSounds = true;
// Apply the changes and update the UI
mySwitch.UpdateUI();
// Add progress bar events
mySwitch.onValueChanged.AddListener(TestFunctionDynamic);
mySwitch.onEvents.AddListener(TestFunction);
mySwitch.offEvents.AddListener(TestFunction);
}
void TestFunctionDynamic(bool value)
{
Debug.Log("Current value: " + value.ToString());
}
void TestFunction()
{
Debug.Log("Test function");
}
}
How can we help?
A premium WordPress theme with an integrated Knowledge Base,
providing 24/7 community-based support.