starOfWords/Assets/Scripts/3.5/MusicManager.cs
portakal ecb1c9edea Initial commit: Star of Words Unity project
Snapshot of the existing Unity 6 language-learning word game before any
refactoring. Adds Unity .gitignore and .gitattributes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-07-05 15:31:20 +03:00

41 lines
No EOL
1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
public class MusicManager : MonoBehaviour
{
[Header("━━━ MÜZIKLER (25 MP3) ━━━━━━━━━━━━━━━━━")]
public AudioClip[] songs;
[Header("━━━ AUDIO SOURCE ━━━━━━━━━━━━━━━━━━━━━━")]
public AudioSource audioSource;
private int lastIndex = -1;
// ============================================================
void Start()
{
PlayRandom();
}
void Update()
{
if (!audioSource.isPlaying)
PlayRandom();
}
// ============================================================
void PlayRandom()
{
if (songs == null || songs.Length == 0) return;
int index;
do
{
index = Random.Range(0, songs.Length);
}
while (index == lastIndex && songs.Length > 1); // aynı şarkı üst üste gelmesin
lastIndex = index;
audioSource.clip = songs[index];
audioSource.Play();
}
}