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

Unexpected symbol '{', I can't figured it out where with my script

Discussion in 'Scripting' started by Ultimate360, Aug 13, 2017.

  1. Ultimate360

    Ultimate360

    Joined:
    Oct 28, 2016
    Posts:
    27
    Hi, I need a quick help... I know it sounds silly, but I'm stock with this error for hours now, wondering what's wrong with my code making this: Assets/Scripts/MusicManager.cs(29,2): error CS1525: Unexpected symbol '{'. I can't just figured it out what's wrong? I'm don't think I'm lacking of open and close curly brackets { } ? Where is it?
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4.  
    5. [RequireComponent(typeof(AudioSource))]
    6. public class MusicManager : MonoBehaviour {
    7.  
    8.     private AudioSource audioSource;
    9.  
    10.     [Tooltip("First to play and the main theme on scene")]
    11.     public AudioClip mainTheme;
    12.     [Tooltip("Normal music that have ending")]
    13.     public List<AudioClip> oneShotMusicList;
    14.     [Tooltip("A short or long looping music that can repeat seamlessly; Note: will play 1-2 times")]
    15.     public List<AudioClip> loopingMusicList;
    16.  
    17.     void Start () {
    18.         audioSource = GetComponent<AudioSource> ();
    19.  
    20.         StartCoroutine (MusicChange ());
    21.     }
    22.  
    23.     IEnumerator MusicChange ()
    24.     {
    25.         yield return new WaitForSeconds(2);
    26.  
    27.         int musicDirector = 0;
    28.         whlie (true)
    29.         { //<-- Assets/Scripts/MusicManager.cs(29,2): error CS1525: Unexpected symbol '{'
    30.             int mainThemeExist = 0;
    31.             oneShotMusicList.RemoveAll (AudioClip => AudioClip == null);
    32.             loopingMusicList.RemoveAll (AudioClip => AudioClip == null);
    33.  
    34.             if (mainTheme != null)
    35.             {
    36.                 mainThemeExist = 1;
    37.             }
    38.  
    39.             int playList = mainThemeExist + oneShotMusicList.Count + loopingMusicList.Count;
    40.             if (playList > 0)
    41.             {
    42.                 int randomizer = Random.Range (0, playList + 1);
    43.  
    44.                 if (mainTheme != null && (randomizer == 0 || musicDirector == 0))
    45.                 {
    46.                     audioSource.clip = mainTheme;
    47.                     musicDirector = 1;
    48.                 }
    49.                 else
    50.                 {
    51.                     for (int i = 1; i < playList; i++)
    52.                     {
    53.                         if (randomizer == i)
    54.                         {
    55.                             if (i <= oneShotMusicList.Count)
    56.                             {
    57.                                 audioSource.clip = oneShotMusicList [i - 1];
    58.                                 musicDirector = 1;
    59.                             }
    60.                             else
    61.                             {
    62.                                 audioSource.clip = loopingMusicList [i - oneShotMusicList.Count - 1];
    63.                                 musicDirector = 2;
    64.                             }
    65.                         }
    66.                     }
    67.                 }
    68.  
    69.                 if (musicDirector == 2)
    70.                     randomizer = Random.Range(0, 2);
    71.                 else
    72.                     randomizer = 0;
    73.  
    74.                 for (int i = 0; i <= randomizer; i++)
    75.                 {
    76.                     audioSource.Play ();
    77.                     yield return new WaitForSeconds(audioSource.clip.length);
    78.                 }
    79.             }
    80.             yield return null;
    81.         }
    82.     }
    83. }
    I'm so sorry, I think I'm back to noob or forgot something. Thank you for your help!
     
    Last edited: Aug 13, 2017
  2. Simo

    Simo

    Joined:
    Sep 16, 2012
    Posts:
    85
    its while and not whlie ;)
     
    Ultimate360 likes this.
  3. Ultimate360

    Ultimate360

    Joined:
    Oct 28, 2016
    Posts:
    27
    :eek: OH! Oh! I'm so stupid, thank you! :D
     
    TaleOf4Gamers likes this.
  4. TaleOf4Gamers

    TaleOf4Gamers

    Joined:
    Nov 15, 2013
    Posts:
    825
    It happens to the best of us.
     
  5. Kiwasi

    Kiwasi

    Joined:
    Dec 5, 2013
    Posts:
    16,860
    For future reference unexpected symbol is often something directly before the symbol the error points to.