2020-02-01 18:53:25 +00:00
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class MusicManager : MonoBehaviour
|
|
|
|
|
{
|
|
|
|
|
public AudioSource musicSource = new AudioSource();
|
2020-02-01 22:25:24 +00:00
|
|
|
|
public AudioClip DayMusic;
|
|
|
|
|
public AudioClip NightMusic;
|
2020-02-01 18:53:25 +00:00
|
|
|
|
|
2020-02-01 22:25:24 +00:00
|
|
|
|
private bool night = false;
|
|
|
|
|
public GameObject Sun = new GameObject();
|
2020-02-01 18:53:25 +00:00
|
|
|
|
// Start is called before the first frame update
|
|
|
|
|
void Start()
|
|
|
|
|
{
|
2020-02-01 22:25:24 +00:00
|
|
|
|
musicSource.PlayOneShot(DayMusic);
|
2020-02-01 18:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Update is called once per frame
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2020-02-01 22:25:24 +00:00
|
|
|
|
float sunRotationX = Sun.transform.localEulerAngles.x;
|
|
|
|
|
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
|
|
|
|
|
|
|
|
|
|
Debug.Log(sunRotationX.ToString());
|
|
|
|
|
if (sunRotationX < 0)
|
|
|
|
|
{
|
|
|
|
|
musicSource.PlayOneShot(NightMusic);
|
|
|
|
|
Debug.Log("It is a Night");
|
|
|
|
|
night = true;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
musicSource.PlayOneShot(DayMusic);
|
|
|
|
|
Debug.Log("It is a Day");
|
|
|
|
|
night = false;
|
|
|
|
|
}
|
2020-02-01 18:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
}
|