- Home /
Question by
l7ssha · Feb 22, 2016 at 02:50 PM ·
c#networkingmusicsynchronizing
Sync Soundtrack over Network
Hello, Create rhythmic music game and I have to synchronize a random music. How can I do this?
For random music I use this script: using UnityEngine; using System.Collections; using UnityEngine.Networking;
public class RamdomMusic : NetworkBehaviour
{
AudioSource audio;
public AudioClip[] myMusic; // declare this as Object array
void Awake()
{
audio = FindObjectOfType<AudioSource>(); //Referencja do AudioSource
audio.clip = myMusic[Random.RandomRange(1, myMusic.Length)] as AudioClip; //Przypisanie Audiosurce.clip do arraya
}
void Start()
{
audio.Play(); //graj na starcie
}
void Update() // Update is called once per frame
{
if (!audio.isPlaying) //jesli audio NIE gra
playRandomMusic(); //reference do losowej muzyki
}
void playRandomMusic()
{
audio.clip = myMusic[Random.Range(0, myMusic.Length)] as AudioClip; //losowanie
audio.Play(); //graj nową muzyke
}
}
Comment
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
How to know if my speakers are mute? c# android/ios 0 Answers
Trying to send command for object without authority - on a networkidenity with local authority 2 Answers
How to synchronize disable and enabling game objects over the network? 0 Answers