GlobalGameJame/Assets/Scripts/DayManager.cs

47 lines
1.1 KiB
C#
Raw Normal View History

2020-02-01 12:30:49 +00:00
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DayManager : MonoBehaviour
{
public int sunSpeed = 30;
2020-02-01 18:31:59 +00:00
private bool night = false;
public AudioSource mainSource = new AudioSource();
public AudioClip dayClip;
public AudioClip nigtClip;
2020-02-01 12:30:49 +00:00
2020-02-01 19:14:33 +00:00
public int daySurvived = 0;
2020-02-01 12:30:49 +00:00
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
2020-02-01 18:31:59 +00:00
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;
2020-02-01 19:14:33 +00:00
daySurvived++;
2020-02-01 18:31:59 +00:00
}
2020-02-01 12:30:49 +00:00
this.gameObject.transform.Rotate(new Vector3(sunSpeed * Time.deltaTime, 0, 0));
}
}