I am trying to do a SongManager object which will be responsible for changing songs. I created a SongManager and a Song script. On runtime SongManager creates as many song buttons as i want each with different variables. Everything seems to work fine except that i cant get to OnClick event to change the songs.I tried many things but i guess its all outdated. Stuff like:
public Button.ButtonClickedEvent OnClickEvent;
or
go.GetComponent<Button>().onClick.AddListener();
Appreciate any help, thank u guys.
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
using UnityEngine.EventSystems;
public class SongManager : MonoBehaviour {
[System.Serializable]
public class Song
{
public string SongName;
public int Unlocked;
public bool isInteractable;
public AudioClip clip;
}
public GameObject button;
public Transform panel;
public List<Song> songList;
void Start ()
{
FillList();
}
void FillList()
{
foreach (var song in songList)
{
GameObject newButton = Instantiate(button) as GameObject;
SongButton songButton = newButton.GetComponent<SongButton>();
songButton.songName.text = song.SongName;
songButton.clip = song.clip;
newButton.transform.SetParent(panel, false);
}
}
}
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class SongButton : MonoBehaviour
{
public Text songName;
public int unlocked;
public AudioClip clip;
}

