AudioSource Array doesn't play,Audio Source doesn't play in Array
I wrote a Code where different audios play in a row by KeyCode. The switch between the audios work but the audio doesn't play. Can someone help me? Here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioPlay : MonoBehaviour
{
public AudioClip[] sounds;
public int x;
AudioSource source;
void Start()
{
x = 0;
//AudioSource audio = GetComponent<AudioSource>();
source = GetComponent<AudioSource>();
source.enabled = true;
source.clip = sounds[x];
}
void Update()
{
source.clip = sounds[x];
source.Play();
if (Input.GetKeyDown(KeyCode.Y))
{
NextAudio();
}
}
public void NextAudio()
{
if (x < 3)
{
x++;
}
else
{
x = 0;
}
}
}
,I wrote a Code where AudioSources play in a row by KeyCode. The switch to the next Audio works but it does'nt play. Can someone help me? here's the code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AudioPlay : MonoBehaviour
{
public AudioClip[] sounds;
public int x;
AudioSource source;
void Start()
{
x = 0;
//AudioSource audio = GetComponent<AudioSource>();
source = GetComponent<AudioSource>();
source.enabled = true;
source.clip = sounds[x];
}
void Update()
{
source.clip = sounds[x];
source.Play();
if (Input.GetKeyDown(KeyCode.Y))
{
NextAudio();
}
}
public void NextAudio()
{
if (x < 3)
{
x++;
}
else
{
x = 0;
}
}
}
Comment