I am trying to play an audio clip, too big to use PlayClipAtPoint() and I will need to stop it later.
public class GridPower: MonoBehaviour {
private AudioSource audiosource;
public AudioClip poweroff;
int k;
void Start ()
{
audiosource= GetComponent<AudioSource>();
k = 1;
}
void Update ()
{
if (PlayLevel1.percentageLoadProductionint < 100 && StateManager.activeState is PlayState && Time.timeSinceLevelLoad > 1 && k== 1)
{
audiosource.clip = poweroff;
audiosource.Play ();
k = 2;
}
}
}
I followed some documentation but unity tells me that there is no AudioSource attached to the game object where the script is located.
Can you help?