Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

error CS1002: ; expected

Discussion in 'Scripting' started by jazzyr, Mar 27, 2021.

  1. jazzyr

    jazzyr

    Joined:
    Nov 27, 2020
    Posts:
    2
    Hello I think this may seem obvious. I am trying to create an audio player in unity following this tutorial



    but I keep getting this message what am I missing
    Assets/AudioManager.cs(48,15): error CS1002: ; expected

    line 48 is
    yeild return null;
    I am using unity 2019.3.13f1

    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4.  
    5. using UnityEngine.UI;
    6. using UnityEngine.Audio;
    7.  
    8. [RequireComponent(typeof(AudioSource))]
    9.  
    10. public class AudioManager : MonoBehaviour
    11. {
    12.  
    13.   public AudioClip[] muiscClips;
    14.   private int currentTrack;
    15.   private AudioSource source;
    16.  
    17.  
    18.     // Start is called before the first frame update
    19.     void Start()
    20.     {
    21.       source = GetComponent<AudioSource>();
    22.  
    23.       //play music
    24.       PlayMusic();
    25.  
    26.  
    27.     }
    28.  
    29.     public void PlayMusic()
    30.     {
    31.       if (source.isPlaying)
    32.       {
    33.         return;
    34.       }
    35.  
    36.       currentTrack--;
    37.       if (currentTrack < 0)
    38.       {
    39.         currentTrack = musicClips.Length - 1;
    40.       }
    41.       StartCoroutine(WaitForMusicEnd());
    42.     }
    43.  
    44.     IEnumerator WaitForMusicEnd()
    45.     {
    46.       while(source.isPlaying)
    47.       {
    48.         yeild return null;
    49.       }
    50.       NextTitle();
    51.  
    52.     }
    53.  
    54.     public void NextTitle()
    55.     {
    56.       source.Stop();
    57.       currentTrack++;
    58.       if(currentTrack > musicClips.Length -1)
    59.       {
    60.         currentTrack = 0;
    61.       }
    62.  
    63.       source.clip = musicClips[currentTrack];
    64.       source.Play();
    65.  
    66.       //show title
    67.  
    68.       StartCoroutine(WaitForMusicEnd());
    69.  
    70.     }
    71. }
    72.  
     
  2. jasonasaad2

    jasonasaad2

    Joined:
    Nov 30, 2020
    Posts:
    51
    You spelled Yield wrong,
    Code (CSharp):
    1. yield return null;
    Just copy that into line 48
     
    Putcho and jazzyr like this.
  3. jazzyr

    jazzyr

    Joined:
    Nov 27, 2020
    Posts:
    2
    thank you! its always the obvious mistakes