- Home /
Day-Night-changing error.
Hello, I think my problem is quiet simple, but can't solve it. In the script i made IF statement, which doesn't execute even if it is true... (this script is attached to directional light). Here is the script:
#pragma strict
var daySpeed : float;
function Start() {
daySpeed = 0.2;
}
function Update() {
transform.Rotate(daySpeed,0,0);
if(transform.rotation.x > 350 && transform.rotation.x < 360) {
Night();
}
else {
daySpeed = 0.2;
}
}
function Night() {
daySpeed = 0.01;
}
Answer by Seizure · Aug 01, 2013 at 03:38 PM
It looks as if you never increment the transform. Try:
#pragma strict
var daySpeed : float;
function Start() {
daySpeed = 0.2;
}
function Update() {
// transform.Rotate(daySpeed,0,0); //Instead of this
//This is C# formatting
transform.EulerAngles = new Vector3 (transform.EulerAngles.x + daySpeed, 0,0);
if(transform.rotation.x > 350 && transform.rotation.x < 360) {
Night();
}
else {
daySpeed = 0.2;
}
}
function Night() {
daySpeed = 0.01;
}
Thanks for response, but in the Unity guide is this nice sentence: "Only use this variable to read and set the angles to absolute values. Don't increment them, as it will fail when the angle exceeds 360 degrees. Use Transform.Rotate ins$$anonymous$$d." In my case, it fails at 90° when I use transform.eulerAngles.
Your answer
Follow this Question
Related Questions
If/else statements working one way, and not the other 0 Answers
Setting Scroll View Width GUILayout 1 Answer
not sure whats happened :S 1 Answer
Passing variables' values between two or more scripts 1 Answer
Code not entering if statement. 1 Answer