• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
Question by Trevor 1 · Mar 29, 2010 at 04:19 PM · errormusicparsingcs8025

Jukebox parsing error

Okay so I know what the code is for (the jukebox player) but for some reason I keep getting a parsing error. Here is what I have, what am I doing wrong? It is in C#.

using UnityEngine; using System.Collections;

JukeboxController jukebox = new JukeboxController(); jukebox.AddClip("mysong", myclip); jukebox.PlayClip("mysong"); jukebox.StopClip();

public class JukeboxController {

 Hashtable jukebox;
 string current_clip;

 public JukeboxController()
 {
     jukebox = new Hashtable();
     current_clip = null;
 }
 // constructor

 public void AddClip(string name, AudioClip clip)
 {
     if (jukebox == null)
     {
         jukebox = new Hashtable();
     } // if

     GameObject obj;
     obj = new GameObject();
     obj.AddComponent("AudioSource");
     obj.audio.clip = clip;
     obj.audio.ignoreListenerVolume = true;
     DontDestroyOnLoad(obj);
     jukebox.Add(name, obj);
 } // AddClip()

 /*
     Play a named audio clip.
     Does not restart the clip if it is played twice in a row.
     Will stop a previously playing clip to play this new clip.
 */
 public void PlayClip(string name)
 {
     if (name == current_clip)
     {
         return;
     } // if
     if (current_clip != null)
     {
         StopClip();
     } // if

     ((GameObject)jukebox[name]).audio.Play();
     current_clip = name;
 } // PlayClip()

 public void StopClip()
 {
     ((GameObject)jukebox[current_clip]).audio.Stop();
 } // StopClip()

}

Comment
Tetrad

People who like this

-1 Show 0
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Eric5h5 · Mar 31, 2010 at 05:20 AM

DontDestroyOnLoad won't work unless the class extends MonoBehaviour. The code at the top (JukeboxController jukebox = etc.) can't be "bare" like that and needs to be inside a function, like Start.

Comment

People who like this

0 Show 0 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image

Answer by qJake · Mar 29, 2010 at 05:56 PM

Haha... you definitely don't need the line in there that says "Usage:", and reading the error message specifically would have pointed you to that exact line of code. Just another reason you shouldn't mindlessly copy and paste code. ;)

Comment
Novodantis 1

People who like this

-1 Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Trevor 1 · Mar 31, 2010 at 04:58 AM 0
Share

a simple answere would have been nice.. So i got rid of that I still get an error. So what now.

avatar image Trevor 1 · Mar 31, 2010 at 04:59 AM 0
Share

answer*

avatar image qJake · Mar 31, 2010 at 08:23 AM 0
Share

I gave you a simple answer, and at the time, your post wasn't properly formatted, so I couldn't see what was going on. The first four lines of your script need to go somewhere else in your game, that's why it was labeled as "Usage", is because that's how you use it. Don't expect anything to work that you just copy and paste and don't take the time to figure out. Did the place where you got this code from explain how to use it, specifically?

avatar image Trevor 1 · Apr 01, 2010 at 02:33 AM 0
Share

Not exactly. I have gotten this from unifycommunity.com but they said it is ment to be used in the main game controller script. I will be honest I am not very good at c# but java i am.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

CS8025 Error (Parsing Error) 1 Answer

Script Errors with C# 1 Answer

Parsing error with my code 3 Answers

Parsing error. No idea what it is or what the problem is. 2 Answers

c# parsing error Help please and the error is at where it says public string Name 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges