GlobalGameJame/Assets/Scripts/MusicManager.cs

49 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
public class MusicManager : NetworkBehaviour
{
public AudioSource musicSource;
public AudioClip DayMusic;
public AudioClip NightMusic;
private bool night = false;
public GameObject Sun;
// Start is called before the first frame update
void Start()
{
if (!isLocalPlayer)
{
return;
}
musicSource.PlayOneShot(DayMusic);
}
// Update is called once per frame
void Update()
{
if (!isLocalPlayer)
{
return;
}
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;
}
}
}