Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by GradyLorenzo · Jul 16, 2013 at 04:11 PM · animationfloatcurvenotupdating

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;
 }
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

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;
Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image GradyLorenzo · Jul 16, 2013 at 04:43 PM 0
Share

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.

avatar image amphoterik · Jul 16, 2013 at 05:19 PM 0
Share

Excellent. If my answer helped you, please select it as the answer. It will help future readers and give you karma.

avatar image GradyLorenzo · Jul 16, 2013 at 07:36 PM 0
Share

Done and done

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges