Good evening, I have an issue with my UI that has 6 buttons. Not 100% sure what is different from the other ui menus I have which does not give the same warning.
There are 6 event systems in the scene. Please ensure there is always exactly one event system in the scene
The warnings come through when the UI becomes active.
The six buttons are the same except the On Click () is set to the corresponding functions.
Would this also be why the PlaySong function or specifically soundSource.Play(); Won’t work?
Script:
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class RadioManager : MonoBehaviour
{
[Header("Radio Interactions")]
[SerializeField] private GameObject selected;
[SerializeField] private TMP_Text songName;
[SerializeField] private TMP_Text songNoCount;
public Outline outline;
[SerializeField] Boolean musicPlaying;
[SerializeField] Boolean insideCollider = false;
[Header("Background")] [SerializeField] private GameObject background;
[Header("Radio Controls")]
[SerializeField] private GameObject radioMenu;
private AudioSource _audioSource;
[Header("Song Playlist")]
[SerializeField] private string playlistPath = Application.streamingAssetsPath + "/Music/";
public int songCount;
[SerializeField] private List<AudioClip> playlist = new List<AudioClip>();
private string[] songNames;
[SerializeField] private int songIndex = 0;
public AudioSource soundSource;
public GameObject ambience;
private void Awake()
{
musicPlaying = false;
// Create Audio Source
_audioSource = gameObject.AddComponent<AudioSource>();
// Interactions off
outline.enabled = false;
selected.SetActive(false);
}
void Start()
{
// Pause menu to be inactive on game start
radioMenu.SetActive(false);
// Create music directory if it does not exist
if (!Directory.Exists("music"))
Directory.CreateDirectory("music");
if (!Directory.Exists(Application.streamingAssetsPath + "/Music/"))
Directory.CreateDirectory(Application.streamingAssetsPath + "/Music/");
// List the songs
LoadAudio();
//GetAllSongs();
// Set count and name in ui
songNoCount.text = "(" + songCount + ")";
songName.text = playlist[songIndex].name;
// Set song in player
soundSource.clip = playlist[songIndex];
}
private void Update()
{
if (insideCollider && Input.GetKeyDown(KeyCode.E))
{
MenuToggleSound();
ToggleRadioMenu();
}
}
public void PlaySong()
{
ambience.SetActive(false);
if(!soundSource.isPlaying)
{
soundSource.Play();
}
}
public void StopSong()
{
soundSource.Stop();
}
public void PauseSong()
{
soundSource.Pause();
ambience.SetActive(true);
}
public void NextSong()
{
songIndex = (songIndex + 1) % songCount;
UpdateTrack(songIndex);
}
public void PreviousSong()
{
songIndex = (songIndex - 1 + songCount) % songCount;
UpdateTrack(songIndex);
}
public void LoopSong()
{
if (soundSource.loop)
{
soundSource.loop = false;
}
else
{
soundSource.loop = true;
}
}
void UpdateTrack(int index)
{
soundSource.clip = playlist[index];
songName.text = playlist[songIndex].name;
}
public void ToggleRadioMenu()
{
radioMenu.SetActive(!radioMenu.activeSelf);
background.SetActive(!background.activeSelf);
if (radioMenu.activeSelf)
{
// Enable cursor
MouseStateCheck.ToggleOn();
UIManager.interactions.SetActive(false);
}
else
{
// Disable cursor
MouseStateCheck.ToggleOff();
UIManager.interactions.SetActive(true);
}
}
private void OnTriggerEnter(Collider other)
{
if (other.CompareTag("Player"))
{
insideCollider = true;
outline.enabled = true;
// Play pickup sound
_audioSource.PlayOneShot(SoundReference.i.selection);
UIManager.interactions.SetActive(true);
if(musicPlaying == false)
UIManager.interactions.GetComponent<Image>().sprite = InteractionsSpriteReference.i.musicOn;
else
UIManager.interactions.GetComponent<Image>().sprite = InteractionsSpriteReference.i.musicOff;
}
}
private void OnTriggerExit(Collider other)
{
if (other.CompareTag("Player"))
{
insideCollider = false;
outline.enabled = false;
UIManager.interactions.SetActive(false);
}
}
private void LoadAudio()
{
// Clear any songs in the playlist
playlist.Clear();
// Get songs in the streaming file
songNames = Directory.GetFiles(Application.streamingAssetsPath + "/Music/", "*.mp3");
songCount = songNames.Length;
for (int i = 0; i < songCount; i++)
{
string path = songNames[i];
string url = string.Format("file://" + path);
Debug.Log(url);
WWW www = new WWW(url);
AudioClip clip = www.GetAudioClip(false);
clip.name = Path.GetFileName(path);
playlist.Add(clip);
}
}
private void MenuToggleSound()
{
soundSource.PlayOneShot(SoundReference.i.menuToggle2);
}
public void ButtonHover()
{
soundSource.PlayOneShot(SoundReference.i.buttonHover);
}
}