GlobalGameJame/Assets/Scripts/DayManager.cs
2020-02-02 13:11:38 +01:00

48 lines
1.1 KiB
C#

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DayManager : MonoBehaviour
{
public int sunSpeed = 30;
private bool night = false;
public AudioSource mainSource = new AudioSource();
public AudioClip dayClip;
public AudioClip nigtClip;
public GuiManager guiManager;
public int daySurvived = 0;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (guiManager != null)
{
guiManager.setWave(daySurvived+1);
}
float sunRotationX = transform.localEulerAngles.x;
sunRotationX = (sunRotationX > 180) ? sunRotationX - 360 : sunRotationX;
if (sunRotationX < 0 && !night)
{
mainSource.PlayOneShot(nigtClip);
night = true;
}
else if (sunRotationX > 0 && night)
{
mainSource.PlayOneShot(dayClip);
night = false;
daySurvived++;
}
this.gameObject.transform.Rotate(new Vector3(sunSpeed * Time.deltaTime, 0, 0));
}
}