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>
41 lines
No EOL
1 KiB
C#
41 lines
No EOL
1 KiB
C#
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();
|
||
}
|
||
} |