Day manager sounds
This commit is contained in:
parent
2b24a98768
commit
af452cb78c
@ -5,6 +5,11 @@ using UnityEngine;
|
|||||||
public class DayManager : MonoBehaviour
|
public class DayManager : MonoBehaviour
|
||||||
{
|
{
|
||||||
public int sunSpeed = 30;
|
public int sunSpeed = 30;
|
||||||
|
private bool night = false;
|
||||||
|
|
||||||
|
public AudioSource mainSource = new AudioSource();
|
||||||
|
public AudioClip dayClip;
|
||||||
|
public AudioClip nigtClip;
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
void Start()
|
void Start()
|
||||||
@ -15,6 +20,23 @@ public class DayManager : MonoBehaviour
|
|||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update()
|
void Update()
|
||||||
{
|
{
|
||||||
|
float sunRotationX = transform.localEulerAngles.x;
|
||||||
|
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
|
||||||
|
|
||||||
|
Debug.Log(sunRotationX.ToString());
|
||||||
|
if (sunRotationX < 0 && !night)
|
||||||
|
{
|
||||||
|
Debug.Log("It is a Night");
|
||||||
|
mainSource.PlayOneShot(nigtClip);
|
||||||
|
night = true;
|
||||||
|
}
|
||||||
|
else if (sunRotationX > 0 && night)
|
||||||
|
{
|
||||||
|
Debug.Log("It is a Day");
|
||||||
|
mainSource.PlayOneShot(dayClip);
|
||||||
|
night = false;
|
||||||
|
}
|
||||||
|
|
||||||
this.gameObject.transform.Rotate(new Vector3(sunSpeed * Time.deltaTime, 0, 0));
|
this.gameObject.transform.Rotate(new Vector3(sunSpeed * Time.deltaTime, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user