Search Unity

Question How to correctly set music listen button of spesific clicked object?

Discussion in 'Audio & Video' started by unity_BF2C52810E8DC793F3A0, Apr 14, 2022.

  1. unity_BF2C52810E8DC793F3A0

    unity_BF2C52810E8DC793F3A0

    Joined:
    Nov 23, 2021
    Posts:
    1
    Hello guys! I have a problem with making "play and stop button" for listening to music. I want to play music of a specific object, on the first click it should play and on the second click stop. But the problem is I can stop music only when touched any part of the screen except listen button(coz' I used "Input.GetMouseButtonDown(0)" ), It should stop when the same button is clicked a second time, but it replay the music.

    Code (CSharp):
    1.  
    2. private void Update()
    3.     {
    4.         if (Input.GetMouseButtonDown(0))
    5.         {
    6.             Listen_IconActive.SetActive(false);
    7.             SongPlayer.Instance.StopBeat();
    8.         }
    9.     }
    10.  
    11.     [System.Obsolete]
    12.     public void OnListenClicked()
    13.     {
    14.         SongPlayer.Instance.LoadBit(Model.name);
    15.         Listen_IconActive.SetActive(true);
    16.         SongPlayer.Instance.PlayBeat(0f);
    17.         if (!File.Exists(Path.Combine(Application.persistentDataPath, GameConstanst.SHORT_BEAT_PATH_RESOURCE, Model.name + ".mp3")))
    18.         {
    19.             Debug.Log("sacrifice 1");
    20.             StartCoroutine(GetMP3(Model.short_beat_url, GameConstanst.SHORT_BEAT_PATH_RESOURCE, Model.name, true));
    21.             Listen_IconActive.SetActive(true);
    22.             SongPlayer.Instance.PlayBeat(0f);
    23.         }
    24.     }
    25.  
    26. Any help would be much appreciated!
     
    Last edited: Apr 16, 2022