Пробовал создать цикл дня и ночи и все получалось, пока не решил, что день и ночь не могут быть одинаковыми по длине(в большинстве случаев). Принялся это менять...
Скорость НЕ меняется, как будто условие в первом if всегда верно. Перелопатил весь скрипт, а причину ошибки так и не отыскал. Не подскажете, в чем здесь может быть проблема?
Синтаксис:
Используется csharp
using UnityEngine;
using System.Collections;
public class DayNight_Cycle: MonoBehaviour {
public int sun_rotation_speed = 0;
public Transform[] sun; //Directional light
private float time_of_day;
public int SunriseTimeSpeed = 0;
public int NoonTimeSpeed = 0;
public int EveningTimeSpeed = 0;
public int MidnightTimeSpeed = 0;
void Start () {
time_of_day = 0;
}
// Update is called once per frame
void Update () {
if (sun[0].rotation.y>=0&&sun[0].rotation.y<=90){
sun[0].Rotate(new Vector3(SunriseTimeSpeed,sun_rotation_speed,0) * Time.deltaTime); // Sunrise
} else
if (sun[0].rotation.y>=90&&sun[0].rotation.y<=180){
sun[0].Rotate(new Vector3(NoonTimeSpeed,sun_rotation_speed, 0) * Time.deltaTime); // Noon
} else
if (sun[0].rotation.y>=180&&sun[0].rotation.y<=270){
sun[0].Rotate(new Vector3(EveningTimeSpeed,sun_rotation_speed,0) * Time.deltaTime); // Evening
} else
if (sun[0].rotation.y>=270&&sun[0].rotation.y<=360) {
sun[0].Rotate(new Vector3(MidnightTimeSpeed,sun_rotation_speed,0) * Time.deltaTime); //Midnight
} else
sun[0].Rotate(new Vector3(sun_rotation_speed,sun_rotation_speed,0) * Time.deltaTime);
time_of_day+=Time.deltaTime;
print(time_of_day);
}
}
using System.Collections;
public class DayNight_Cycle: MonoBehaviour {
public int sun_rotation_speed = 0;
public Transform[] sun; //Directional light
private float time_of_day;
public int SunriseTimeSpeed = 0;
public int NoonTimeSpeed = 0;
public int EveningTimeSpeed = 0;
public int MidnightTimeSpeed = 0;
void Start () {
time_of_day = 0;
}
// Update is called once per frame
void Update () {
if (sun[0].rotation.y>=0&&sun[0].rotation.y<=90){
sun[0].Rotate(new Vector3(SunriseTimeSpeed,sun_rotation_speed,0) * Time.deltaTime); // Sunrise
} else
if (sun[0].rotation.y>=90&&sun[0].rotation.y<=180){
sun[0].Rotate(new Vector3(NoonTimeSpeed,sun_rotation_speed, 0) * Time.deltaTime); // Noon
} else
if (sun[0].rotation.y>=180&&sun[0].rotation.y<=270){
sun[0].Rotate(new Vector3(EveningTimeSpeed,sun_rotation_speed,0) * Time.deltaTime); // Evening
} else
if (sun[0].rotation.y>=270&&sun[0].rotation.y<=360) {
sun[0].Rotate(new Vector3(MidnightTimeSpeed,sun_rotation_speed,0) * Time.deltaTime); //Midnight
} else
sun[0].Rotate(new Vector3(sun_rotation_speed,sun_rotation_speed,0) * Time.deltaTime);
time_of_day+=Time.deltaTime;
print(time_of_day);
}
}