- Home /
GUI Button On Click Event
I am trying to build a simple AR demo using Vuforia ground plane and Unity.
I have an object with an animation on it and I want to have a GUI button that turns said object on, then another GUI button that plays and pauses the animation. I have gotten this all working. The issue I am having is when the object is placed and hidden, it always ends up placed at the first augmentation position. I want the object position to be updated to the current reticle location after the augmentation has been destroyed and recreated. I believe the issue I have is my button click actions do not occur in the Update function. Below is the code I have on the canvas object.
I have tried googling this to no avail, and also tried referencing Vuforia's sample project code with little luck. I am extremely new to C# as well. Can anyone help point me in the right direction?
public class MenuScript : MonoBehaviour
{
#region PUBLIC_MEMBERS
public Text buttonText;
public Text buttonPlay;
public GameObject Cell;
public GameObject PlayBtn;
public GameObject showButton;
public Animation anim;
#endregion
void Start()
{
buttonText.text = "Show Cell";
buttonPlay.text = "Play";
Cell.SetActive(false);
}
public void Button_Click(float newValue)
{
{
//Cell.SetActive(!Cell.activeInHierarchy);
if (buttonText.text == "Show Cell")
{
buttonText.text = "Hide Cell";
PlayBtn.SetActive(true);
Cell.SetActive(true);
}
else if (buttonText.text == "Hide Cell")
{
buttonText.text = "Show Cell";
PlayBtn.SetActive(false);
Cell.SetActive(false);
}
}
}
public void ButtonPlay(float newValue)
{
if (buttonPlay.text == "Play")
{
buttonPlay.text = "Pause";
Cell.GetComponent<Animation>().Play("cellAnimation2");
Cell.GetComponent<Animation>()["cellAnimation2"].speed = 2f;
}
else if (buttonPlay.text == "Pause")
{
buttonPlay.text = "Resume";
Cell.GetComponent<Animation>()["cellAnimation2"].speed = 0f;
}
else if (buttonPlay.text == "Resume")
{
buttonPlay.text = "Pause";
Cell.GetComponent<Animation>()["cellAnimation2"].speed = 2f;
}
}
}
Your answer
Follow this Question
Related Questions
How to drag objects from UI into scen 3 Answers
Runtime Add/Remove C# Script 2 Answers
How to select an Game Object from an Item List 0 Answers
How to make a Interactive Computer Screen in Unity 5.5? 1 Answer