Conversation_Trigger_Script.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. public class Conversation_Trigger_Script : MonoBehaviour
  5. {
  6. private AudioSource audioPlayer;
  7. private Queue<Conversation_Line> lines = new Queue<Conversation_Line>();
  8. private bool triggered;
  9. void Start() {
  10. audioPlayer = gameObject.AddComponent<AudioSource>();
  11. foreach (Conversation_Line line in GetComponents<Conversation_Line>()) {
  12. lines.Enqueue(line);
  13. }
  14. }
  15. void Update() {
  16. if (triggered) {
  17. if (lines.Count > 0) {
  18. Static_GlobalStats.paused = true;
  19. if (!audioPlayer.isPlaying) {
  20. Conversation_Line line = lines.Dequeue();
  21. audioPlayer.clip = line.clip;
  22. audioPlayer.Play();
  23. if (line.bauteil) {
  24. Static_GlobalStats.bauteileLevel++;
  25. }
  26. }
  27. }
  28. else if (!audioPlayer.isPlaying) {
  29. Static_GlobalStats.paused = false;
  30. Destroy(gameObject);
  31. }
  32. }
  33. }
  34. void OnTriggerEnter2D(Collider2D col) {
  35. if (!triggered && col && col.gameObject && col.gameObject.tag == "Player") {
  36. triggered = true;
  37. }
  38. }
  39. }