Advertisement
Guest User

Untitled

a guest
Feb 16th, 2020
126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4.  
  5. public class CameraLerp : MonoBehaviour
  6. {
  7. public Transform target;
  8. public float smoothing;
  9. public Vector2 maxPosistion;
  10. public Vector2 minPosition;
  11. private AudioManager audioManager;
  12. float timer = 10;
  13. Sound MorningBGM;
  14. Sound NightBGM;
  15. Sound CaveBGM;
  16. Sound curBGM;
  17. //Sound WildareaBGM;
  18. List<string> dayTimeSounds = new List<string>();
  19. List<string> eveningTimeSounds = new List<string>();
  20.  
  21. void Start()
  22. {
  23. audioManager = GameObject.FindObjectOfType<AudioManager>();
  24. transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);
  25. dayTimeSounds.Add("MorningSE1");
  26. dayTimeSounds.Add("MorningSE2");
  27. eveningTimeSounds.Add("EveningSE1");
  28. eveningTimeSounds.Add("EveningSE2");
  29. MorningBGM = audioManager.GetSound("VillageBGM");
  30. NightBGM = audioManager.GetSound("NightAmbi");
  31. CaveBGM = audioManager.GetSound("MineAreaBGM");
  32. //WildareaBGM = audioManager.GetSound("AdventureBGM");
  33.  
  34.  
  35.  
  36. }
  37.  
  38. private void Update()
  39. {
  40. PlayBGM();
  41. }
  42. // Update is called once per frame
  43. void LateUpdate()
  44. {
  45. Vector3 targetPosition = new Vector3(target.position.x, target.position.y, transform.position.z);
  46. //targetPosition.x = Mathf.Clamp(targetPosition.x, minPosition.x, maxPosistion.x);
  47. //targetPosition.y = Mathf.Clamp(targetPosition.y, minPosition.y, maxPosistion.y);
  48.  
  49. transform.position = targetPosition;
  50. // transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing);
  51.  
  52.  
  53. timer -= Time.deltaTime;
  54.  
  55. audioManager = AudioManager.instance;
  56.  
  57. if (audioManager == null)
  58. {
  59.  
  60. Debug.LogError("AM Not Found");
  61. }
  62.  
  63. if (timer <= 0)
  64. {
  65. timer = Random.Range(0, 20);
  66.  
  67. if (GameTimeManager.Daytime)
  68. {
  69.  
  70. audioManager.PlaySound(dayTimeSounds[Random.Range(0, dayTimeSounds.Count)]);
  71.  
  72. }
  73.  
  74. if (GameTimeManager.Evening)
  75. {
  76.  
  77. audioManager.PlaySound(eveningTimeSounds[Random.Range(0, eveningTimeSounds.Count)]);
  78.  
  79. }
  80.  
  81. if (GameTimeManager.Night)
  82. {
  83.  
  84. }
  85. }
  86. }
  87.  
  88. public void PlayBGM()
  89. {
  90. if (curBGM == null)
  91. {
  92. curBGM = GetcurBGM();
  93.  
  94. curBGM.Play(false);
  95.  
  96. }
  97.  
  98. else
  99. {
  100. if (curBGM != null)
  101. {
  102. curBGM.Stop();
  103. curBGM = null;
  104. }
  105. }
  106. if (curBGM != null)
  107. {
  108. if (curBGM != GetcurBGM())
  109. {
  110. curBGM.Stop();
  111. curBGM = GetcurBGM();
  112. curBGM.Play(false);
  113. }
  114. if (!curBGM.source.isPlaying)
  115. {
  116. curBGM.Play(false);
  117. }
  118. }
  119. }
  120.  
  121. public Sound GetcurBGM()
  122. {
  123. Sound FBGM = MorningBGM;
  124. if (Map.currentMap == 1)
  125. {
  126. FBGM = CaveBGM;
  127. }
  128. if (GameTimeManager.Daytime && Map.currentMap == 0)
  129. {
  130.  
  131. FBGM = MorningBGM;
  132. }
  133. else if (GameTimeManager.Night && Map.currentMap == 0 || GameTimeManager.Night && Map.currentMap == 2)
  134. {
  135. FBGM = NightBGM;
  136.  
  137. }
  138.  
  139. return FBGM;
  140. }
  141. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement