0% found this document useful (0 votes)
10 views2 pages

Unity Toggle Switch Animation Script

Uploaded by

amaan8pool
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Unity Toggle Switch Animation Script

Uploaded by

amaan8pool
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

using UnityEngine;

using [Link];

public class ToggleSwitch : MonoBehaviour


{

public Animator modelAnimator;

void Start()
{
// Make sure to assign the Animator component to the public variable in the
Inspector
if (modelAnimator == null)
{
[Link]("Model Animator not assigned!");
}
}

public void PlayIdleAnimation()


{
[Link]("Idle"); // Replace "Idle" with the name of your idle
animation
}

public void PlayWalkAnimation()


{
[Link]("Walk"); // Replace "Walk" with the name of your walk
animation
}
}

private bool isOn = false;


private Text buttonText;

void Start()
{
// Assuming the Text component is on the same GameObject as the Button
buttonText = GetComponentInChildren<Text>();
UpdateButtonText();
}

public void OnButtonClick()


{
isOn = !isOn;
UpdateButtonText();
[Link]();

// Add any additional actions you want to perform when the switch is
toggled
}
private void UpdateButtonText()
{
[Link] = isOn ? "ON" : "OFF";
}
}

You might also like