- Home /
Question by
Anonyymi · Jul 14, 2015 at 12:50 PM ·
unity 5javascriptlagdaycycle
javascript drops over 30 fps
Is here something to do with this script. It lags very much and drops over 30 frames. It is day and night script what calculates time, moves sun etc.
#pragma strict
public var Sun : Light;
var stars : GameObject;
public var secondsInFullDay : float = 120f;
public var currentTimeOfDay : float;
public var timeMultiplier : float = 1f;
var sunInitialIntensity : float;
function Start () {
sunInitialIntensity = Sun.intensity;
}
function Update () {
UpdateSun();
currentTimeOfDay += (Time.deltaTime / secondsInFullDay) * timeMultiplier;
if (currentTimeOfDay >= 1) {
currentTimeOfDay = 0;
}
}
function UpdateSun(){
Sun.transform.localRotation = Quaternion.Euler((currentTimeOfDay * 360f) - 90, 170, 0);
var intensityMultiplier : float = 1;
if (currentTimeOfDay <= 0.23f || currentTimeOfDay >= 0.75f) {
intensityMultiplier = 0;
}
else if (currentTimeOfDay <= 0.25f) {
intensityMultiplier = Mathf.Clamp01((currentTimeOfDay - 0.23f) * (1 / 0.02f));
}
else if (currentTimeOfDay >= 0.73f) {
intensityMultiplier = Mathf.Clamp01(1 - ((currentTimeOfDay - 0.73f) * (1 / 0.02f)));
}
if(currentTimeOfDay < 0.197636){
stars.SetActive(true);
}
if(currentTimeOfDay > 0.197636 && currentTimeOfDay < 0.7762121){
stars.SetActive(false);
}
if(currentTimeOfDay > 0.7762121){
stars.SetActive(true);
}
Sun.intensity = sunInitialIntensity * intensityMultiplier;
}
Comment
Your answer
Follow this Question
Related Questions
Cannot remove sprite using destroy 1 Answer
Passing variables' values between two or more scripts 1 Answer
Setting Scroll View Width GUILayout 1 Answer
Can i use Standard Assets into my project? 2 Answers
Script sets color to multiple objects from instead of only one object with Random.range() 0 Answers