Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- public class CameraLerp : MonoBehaviour
- {
- public Transform target;
- public float smoothing;
- public Vector2 maxPosistion;
- public Vector2 minPosition;
- private AudioManager audioManager;
- float timer = 10;
- Sound MorningBGM;
- Sound NightBGM;
- Sound CaveBGM;
- Sound curBGM;
- //Sound WildareaBGM;
- List<string> dayTimeSounds = new List<string>();
- List<string> eveningTimeSounds = new List<string>();
- void Start()
- {
- audioManager = GameObject.FindObjectOfType<AudioManager>();
- transform.position = new Vector3(target.position.x, target.position.y, transform.position.z);
- dayTimeSounds.Add("MorningSE1");
- dayTimeSounds.Add("MorningSE2");
- eveningTimeSounds.Add("EveningSE1");
- eveningTimeSounds.Add("EveningSE2");
- MorningBGM = audioManager.GetSound("VillageBGM");
- NightBGM = audioManager.GetSound("NightAmbi");
- CaveBGM = audioManager.GetSound("MineAreaBGM");
- //WildareaBGM = audioManager.GetSound("AdventureBGM");
- }
- private void Update()
- {
- PlayBGM();
- }
- // Update is called once per frame
- void LateUpdate()
- {
- Vector3 targetPosition = new Vector3(target.position.x, target.position.y, transform.position.z);
- //targetPosition.x = Mathf.Clamp(targetPosition.x, minPosition.x, maxPosistion.x);
- //targetPosition.y = Mathf.Clamp(targetPosition.y, minPosition.y, maxPosistion.y);
- transform.position = targetPosition;
- // transform.position = Vector3.Lerp(transform.position, targetPosition, smoothing);
- timer -= Time.deltaTime;
- audioManager = AudioManager.instance;
- if (audioManager == null)
- {
- Debug.LogError("AM Not Found");
- }
- if (timer <= 0)
- {
- timer = Random.Range(0, 20);
- if (GameTimeManager.Daytime)
- {
- audioManager.PlaySound(dayTimeSounds[Random.Range(0, dayTimeSounds.Count)]);
- }
- if (GameTimeManager.Evening)
- {
- audioManager.PlaySound(eveningTimeSounds[Random.Range(0, eveningTimeSounds.Count)]);
- }
- if (GameTimeManager.Night)
- {
- }
- }
- }
- public void PlayBGM()
- {
- if (curBGM == null)
- {
- curBGM = GetcurBGM();
- curBGM.Play(false);
- }
- else
- {
- if (curBGM != null)
- {
- curBGM.Stop();
- curBGM = null;
- }
- }
- if (curBGM != null)
- {
- if (curBGM != GetcurBGM())
- {
- curBGM.Stop();
- curBGM = GetcurBGM();
- curBGM.Play(false);
- }
- if (!curBGM.source.isPlaying)
- {
- curBGM.Play(false);
- }
- }
- }
- public Sound GetcurBGM()
- {
- Sound FBGM = MorningBGM;
- if (Map.currentMap == 1)
- {
- FBGM = CaveBGM;
- }
- if (GameTimeManager.Daytime && Map.currentMap == 0)
- {
- FBGM = MorningBGM;
- }
- else if (GameTimeManager.Night && Map.currentMap == 0 || GameTimeManager.Night && Map.currentMap == 2)
- {
- FBGM = NightBGM;
- }
- return FBGM;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement