dronkowitz

TriggerDialog.cs

Jun 28th, 2021 (edited)
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.14 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class TriggerDialog : MonoBehaviour
  6. {
  7.     public List<AudioClip> dialogs = new List<AudioClip>();
  8.     private bool dialogread;
  9.     public AudioSource omochaoTriggerDisable;
  10.     public bool pause = false;
  11.     // Start is called before the first frame update
  12.     void Start()
  13.     {
  14.  
  15.     }
  16.  
  17.     // Update is called once per frame
  18.     void Update()
  19.     {
  20.  
  21.     }
  22.     private void OnTriggerEnter(Collider other)
  23.     {
  24.         if (dialogread == false && other.tag == "Player")
  25.         {
  26.             dialogread = true;
  27.  
  28.             StartCoroutine(ReadDialog());
  29.         }
  30.     }
  31.     public IEnumerator ReadDialog()
  32.     {
  33.        
  34.         int counter = 0;
  35.            
  36.         while (counter < dialogs.Count)
  37.         {
  38.             omochaoTriggerDisable.clip = dialogs[counter];
  39.             omochaoTriggerDisable.Play();
  40.             while (omochaoTriggerDisable.isPlaying || pause)
  41.             {
  42.                 yield return new WaitForSeconds(Time.deltaTime);
  43.             }
  44.             counter += 1;
  45.         }
  46.         yield return null;
  47.     }
  48. }
  49.  
Add Comment
Please, Sign In to add comment