my daylight cycle is crashing unity whenever it runs (not so much crashing as permanently freezing) if anyone could point out why it would be awesome this is my first time uploading a question so i have no idea how to format it
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DayCycle : MonoBehaviour {
public Light lt;
public int daytime = 5;
public int nighttime = 5;
public bool Up;
public bool Down;
private float value;
public int time;
private bool running;
// Use this for initialization
void Start()
{
n2d();
lt = GetComponent();
lt.intensity = 1;
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
if (Up == true)
{
value = value + 0.05f;
lt.intensity = value;
}
if (Down == true)
{
value = value - 0.05f;
lt.intensity = value;
}
}
IEnumerator day()
{
Debug.Log("its daytime");
time = 1;
yield return new WaitForSeconds(daytime);
d2n();
}
IEnumerator night()
{
Debug.Log("its nighttime");
time = 3;
yield return new WaitForSeconds(nighttime);
n2d();
}
void n2d()
{
Debug.Log("its dawn");
time = 0;
running = true;
while (running)
{
Up = true;
if (value >= 1f)
{
Up = false;
value = 1;
lt.intensity = value;
running = false;
}
}
StartCoroutine(day());
}
void d2n()
{
Debug.Log("its dusk");
time = 2;
running = true;
while (running)
{
Down = true;
if (value <= 0f)
{
Down = false;
value = 0;
lt.intensity = value;
running = false;
}
}
StartCoroutine(night());
}
},my daylight cycle is crashing unity whenever it runs (not so much crashing as permanently freezing) if anyone could point out why it would be awesome this is my first time uploading a question so i have no idea how to format it but here is the code -
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DayCycle : MonoBehaviour {
public Light lt;
public int daytime = 5;
public int nighttime = 5;
public bool Up;
public bool Down;
private float value;
public int time;
private bool running;
// Use this for initialization
void Start()
{
n2d();
lt = GetComponent();
lt.intensity = 1;
}
// Update is called once per frame
void Update()
{
}
private void FixedUpdate()
{
if (Up == true)
{
value = value + 0.05f;
lt.intensity = value;
}
if (Down == true)
{
value = value - 0.05f;
lt.intensity = value;
}
}
IEnumerator day()
{
Debug.Log("its daytime");
time = 1;
yield return new WaitForSeconds(daytime);
d2n();
}
IEnumerator night()
{
Debug.Log("its nighttime");
time = 3;
yield return new WaitForSeconds(nighttime);
n2d();
}
void n2d()
{
Debug.Log("its dawn");
time = 0;
running = true;
while (running)
{
Up = true;
if (value >= 1f)
{
Up = false;
value = 1;
lt.intensity = value;
running = false;
}
}
StartCoroutine(day());
}
void d2n()
{
Debug.Log("its dusk");
time = 2;
running = true;
while (running)
{
Down = true;
if (value <= 0f)
{
Down = false;
value = 0;
lt.intensity = value;
running = false;
}
}
StartCoroutine(night());
}
}
↧