Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • 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
0
Question by PaxStyle · Mar 27, 2014 at 06:37 PM · playerlistmusicsong

Next song problem (music player)

Hi guys, i did this music player, the problem is that if i put for example ten song number, and drag them in song list, when i arrived at the last song (10 for this case) and click on the next song, the script read more than ten songs (it reads infinite songs) How can i set the song limit at 10? I wrote var SongNumber : int = 10; but don't work :/

 var CurrentSong : AudioClip = null;
 var SongList : AudioClip[];
 var gSkin : GUISkin;
 var SongName : String;
 var Music : AudioSource;
 //per usare lo stex input!
 var on : boolean; 
  
  
 var SongNumber : int = 10;
 
 var showGUI : boolean = false;
 
 
 //Volume Audio 
  var hSliderValue : float = 0.0;
  
  
 function Start(){
 
     
     CurrentSong = SongList[SongNumber];
     Music = gameObject.GetComponent(AudioSource);
     Music.loop = false;
     Music.playOnAwake = false;
     Music.clip = CurrentSong;
     Music.volume = 2;
  
 audio.Play();
  
 NextSong();
 
 }
 
 function Update () {
 
 
 //Volume Audio 
 audio.volume = hSliderValue; 
  
 SongName = CurrentSong.name;
  
 Music = gameObject.GetComponent(AudioSource);
 Music.clip = CurrentSong;
  
 
 
 if (SongNumber > SongList.length - 1)
 {
     SongNumber = 0;
 }
 if (SongNumber < 0)
 {
     SongNumber = SongList.length - 1;
 }
 
 }
 
 
 
 
 
 function OnMouseDown () {
     if (Input.GetMouseButton){
     
     //Per usare lo stex Input!
     on= !on;
     
     if (!on) {
     showGUI = true;
     }
     if (on) {
     showGUI = false;
        
 }
 }
 }
 
 
 
  
 function OnGUI(){
 
 if(showGUI){
 
 
 
 GUI.skin = gSkin;
  
 GUI.Box(Rect(10, Screen.height-125, 420, 130), SongName);
 
 
 //Volume Audio
 hSliderValue = GUI.HorizontalSlider (Rect (180, Screen.height-28, 180, 100), hSliderValue, 0.0, 1.0);
 
  
 if(GUI.Button(Rect(30, Screen.height-41, 40, 40), "<<")){
     SongNumber -= 1;
     CurrentSong = SongList[SongNumber];
     Wait();
 }
  
 if(audio.isPlaying){
     if(GUI.Button(Rect(75, Screen.height-41, 40, 40), "||")){
        audio.Pause();
     }
 }
  
 if(!audio.isPlaying){
     if(GUI.Button(Rect(75, Screen.height-41, 40, 40), ">")){
        audio.Play();
     }
 }
  
 if(GUI.Button(Rect(120, Screen.height-41, 40, 40), ">>")){
     SongNumber += 1;
     CurrentSong = SongList[SongNumber];
     Wait();
 }
  
 }
 }
  
 function Wait(){
 yield WaitForSeconds(0.05);
 audio.Play();
  
 }
  
 function NextSong(){
 yield WaitForSeconds (audio.clip.length);
     SongNumber += 1;
     CurrentSong = SongList[SongNumber];
     Wait();
 }
Comment
Add comment · Show 2
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 PaxStyle · Mar 28, 2014 at 02:11 PM 0
Share

someone can help me please?

avatar image Graham-Dunnett ♦♦ · Mar 28, 2014 at 02:21 PM 0
Share

Lines 98, 116 and 132 where you change the SongNumber you probably want to check that you have a number greater or equal to zero, and less than the length of the SongList[].

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by AlucardJay · Mar 28, 2014 at 02:23 PM

lines 48-55 should be where you increase or decrease the value SongNumber, not in Update. Example :

At line 98 :

 SongNumber -= 1;
 if (SongNumber < 0)
 {
     SongNumber = SongList.length - 1;
 }

At line 116 :

 SongNumber += 1;
 if (SongNumber > SongList.length - 1)
 {
     SongNumber = 0;
 }
Comment
Add comment · 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

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.

Follow this Question

Answers Answers and Comments

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

A node in a childnode? 1 Answer

How to make volume continually go down in C#Script ? 1 Answer

iOS Music Control 0 Answers

How to stop audio in a scene when DontDestroyOnLoad was already called? 1 Answer

Unity and IOS Music Player 0 Answers


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