- Home /
Float variable not even updating?
So I've got one script, called "Timekeeper", which does exactly what you'd think, and another script called "SkyEffects". SkyEffects needs a number between 0 and 1 to control the blend of two cubemaps in my skybox material, so the simple answer is to take the secondOfDay from Timekeeper, and divide it by 86400 (because there are 86400 seconds in a day).
The problem is that Unity doesn't seem to want to do even simple math, and the variable SkyboxBlendFactor isn't updating at all. What's more, the AnimationCurve on line 2 of SkyEffects defines keyframes, but those keyframes aren't shown in Unity.
Timekeeper.js:
static var hours : int;
static var minutes : int;
static var seconds : int;
static var secondOfDay : int;
var speed : float;
var syncWithSystemTime : boolean;
function Start () {
if(syncWithSystemTime){
secondOfDay = (System.DateTime.Now.Hour * 3600) + (System.DateTime.Now.Minute * 60) + (System.DateTime.Now.Second);
}
InvokeRepeating ("countUp", 0, speed);
}
function countUp () {
if(secondOfDay < 86400)
secondOfDay ++;
else
secondOfDay = 0;
}
function Update () {
hours = secondOfDay / 3600;
minutes = (secondOfDay / 60) - (hours * 60);
seconds = secondOfDay - (minutes *60);
//print (secondOfDay.ToString());
}
SkyEffects.js
var SkyboxMaterial: Material;
var SkyboxBlendCurve: AnimationCurve = new AnimationCurve(Keyframe(0,0), Keyframe(.20, 0), Keyframe(.29, 1), Keyframe(.79, 1), Keyframe(.87, 0), Keyframe(1, 0));
var SkyboxBlendFactor: float;
function Update () {
SkyboxBlendFactor = Timekeeper.secondOfDay / 86400;
}
Answer by amphoterik · Jul 16, 2013 at 04:29 PM
This is integer division. You need to change secondOfDay to a float OR cast it as a float when you divide it. More information is here: http://stackoverflow.com/questions/10851273/why-integer-division-in-c-sharp-returns-an-integer-but-not-a-float
EDIT, try:
SkyboxBlendFactor = Timekeeper.secondOfDay / 86400.0f;
Thank you, good sir. You are quite helpful. What's the word on the Animation Curve not updating?
EDIT: changing to var SkyboxBlendCurve = new AnimationCurve fixed it.
Excellent. If my answer helped you, please select it as the answer. It will help future readers and give you karma.
Your answer
Follow this Question
Related Questions
Parameterized Animation Clip 0 Answers
Animate mode does not contain definition for GetCurveBindings 2 Answers
Animation not working 1 Answer
Child doesn't play animation. Any help? 1 Answer
Animations from 3DS Max not playing 1 Answer