• 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", w$$anonymous$$ch does exactly what you'd t$$anonymous$$nk, 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

T$$anonymous$$s 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
avatar image amphoterik · Jul 16, 2013 at 05:19 PM 0
Share
avatar image GradyLorenzo · Jul 16, 2013 at 07:36 PM 0
Share

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

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

Random float parameter for idle animations 1 Answer

Verctor3 isnt updating with variables 1 Answer

Mecanim ik curve 0 Answers

Simple question about iTween with float 0 Answers

Animation not found, but animation plays. 2 Answers


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