119 lines
2.7 KiB
C#
119 lines
2.7 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
public class StartIntro : MonoBehaviour
|
|
{
|
|
public AudioClip clipOne; // Reference to the audio clip
|
|
public AudioClip clipTwo;
|
|
public AudioClip clipThree;
|
|
public GameObject audioObject;
|
|
public GameObject contract;
|
|
private AudioSource audioSource; // Reference to the AudioSource component
|
|
public delegate void Callback();
|
|
private Callback onFinished;
|
|
public GameObject loadingCar;
|
|
|
|
|
|
private bool done;
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
|
|
}
|
|
|
|
public void PlayFirstAudio()
|
|
{
|
|
Debug.Log("PlayFirstAudio");
|
|
if (clipOne != null)
|
|
{
|
|
|
|
audioSource.clip = clipOne;
|
|
}
|
|
if (audioSource != null && audioSource.clip != null)
|
|
{
|
|
audioSource.Play();
|
|
StartCoroutine(CheckIfAudioFinished());
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public System.Collections.IEnumerator CheckIfAudioFinished()
|
|
{
|
|
Debug.Log("Audio start Playing!");
|
|
// Wait until the audio finishes playing
|
|
while (audioSource.isPlaying)
|
|
{
|
|
yield return null; // Wait for the next frame
|
|
}
|
|
yield return new WaitForSeconds(2);
|
|
ShowContractAndPlaySecond();
|
|
Debug.Log("Audio Finished Playing!");
|
|
}
|
|
|
|
public void ShowContractAndPlaySecond()
|
|
{
|
|
audioSource.Stop();
|
|
audioSource.clip = clipTwo;
|
|
contract.SetActive(true);
|
|
audioSource.Play();
|
|
|
|
}
|
|
|
|
public void PlayLastOne()
|
|
{
|
|
|
|
contract.SetActive(false);
|
|
audioSource.Stop();
|
|
audioSource.clip = clipThree;
|
|
if (audioSource != null && audioSource.clip != null)
|
|
{
|
|
audioSource.Play();
|
|
StartCoroutine(CheckIfLastAudioFinished());
|
|
}
|
|
}
|
|
|
|
private System.Collections.IEnumerator CheckIfLastAudioFinished()
|
|
{
|
|
// Wait until the audio finishes playing
|
|
while (audioSource.isPlaying)
|
|
{
|
|
yield return null; // Wait for the next frame
|
|
}
|
|
|
|
Debug.Log("Audio Finished Playing!");
|
|
audioObject.SetActive(false);
|
|
done = true;
|
|
}
|
|
|
|
// Update is called once per frame
|
|
void Update()
|
|
{
|
|
|
|
}
|
|
|
|
public IEnumerator introEnter(Callback callback)
|
|
{
|
|
loadingCar.SetActive(false);
|
|
done = false;
|
|
audioObject.SetActive(true);
|
|
audioSource = audioObject.GetComponent<AudioSource>();
|
|
|
|
onFinished = callback;
|
|
PlayFirstAudio();
|
|
|
|
while (!done)
|
|
{
|
|
yield return null; // Ensure the coroutine properly waits
|
|
}
|
|
loadingCar.SetActive(true);
|
|
onFinished?.Invoke();
|
|
}
|
|
|
|
|
|
}
|