multiple buttons not working
i have multiple buttons and the code i have attached below the buttons don't work when i press them, while searching for solutions i found out that we have to create a local variable in the foreach but im a noob to programming i wasnt able to understand how to do it with respect to the code i have
void Update()
{
StateManager sm = TrackerManager.Instance.GetStateManager();
IEnumerable<TrackableBehaviour> tbs = sm.GetActiveTrackableBehaviours();
foreach (TrackableBehaviour tb in tbs)
{
string name = tb.TrackableName;
ImageTarget it = tb.Trackable as ImageTarget;
Vector2 size = it.GetSize();
Debug.Log(" Active image target:" +name + " -size:" +size.x +","+size.y);
MovieTitle.GetComponent<Text>().text = name;
Timeline.gameObject.SetActive(true);
castButton.gameObject.SetActive(true);
songsButton.gameObject.SetActive(true);
if (name == "ARMarker2"){
castButton.GetComponent<Button>().onClick.AddListener(delegate {
setCastActive();
});
songsButton.GetComponent<Button>().onClick.AddListener(delegate {
setSongsActive();
});
MovieTitle.GetComponent<Text>().text = "SHOLAY";
}
/* if (name == "ARMarker1")
{
ButtonAction.GetComponent<Button>().onClick.AddListener(delegate {
playSound(" Sounds / HelloBabyGirl");
});
TextDescription.GetComponent<Text>().text = " A robot is a mechanical or virtual artificial agent, usually an electromechanical machine that is guided by a computer program or electronic circuitry, and thus a type of an embedded system.";
}*/
}
}
//function to play sound
void playSound(string ss)
{
clipTarget = (AudioClip)Resources.Load(ss);
soundTarget.clip = clipTarget;
soundTarget.loop = false;
soundTarget.playOnAwake = false;
soundTarget.Play();
}
void setCastActive() {
castImage.gameObject.SetActive(true);
Timeline.gameObject.SetActive(false);
songsImage.gameObject.SetActive(false);
}
void setSongsActive() {
castImage.gameObject.SetActive(false);
songsImage.gameObject.SetActive(true);
Timeline.gameObject.SetActive(false);
}
void setBRollActive() { }
void setFactsActive() { }
void setAwardsActive() { }
}
}
Comment
What kind of buttons are these and how are you 'pressing' them?
Your answer
Follow this Question
Related Questions
How do I press an UI button with Gamepad controls? 0 Answers
Button AddListener - pass in a UnityAction 0 Answers
UI Sprite not changing when button is pressed 1 Answer
UI button not working (2D) [Solved] 2 Answers
Using two events 0 Answers