Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

event trigered by timeline

Discussion in 'Scripting' started by seefeldt81, Dec 10, 2007.

  1. seefeldt81

    seefeldt81

    Joined:
    Dec 7, 2007
    Posts:
    33
    hello I just started using unity 6 days ago and I'm looking for sample script that trigers an event with the timeline?

    Thankyou for your time
     
  2. AaronC

    AaronC

    Joined:
    Mar 6, 2006
    Posts:
    3,552
    Not sure what you mean precisely, but time based events can be done by:
    Code (csharp):
    1.  
    2. function Start(){
    3. print("0 seconds");
    4. yield WaitForSeconds(3);
    5. print("3 seconds");
    6. }
    Type thing
    AC
     
  3. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    I have also used FixedUpdate function to get 1/50 second accuracy.

    http://unity3d.com/support/documentation/ScriptReference/MonoBehaviour.FixedUpdate.html

    For example, make a counter, that are increased every "frame" in FixedUpdate function. As every count means 1/50s, you can trigger events based on the value of that counter. Or if repeated events are needed, then something like "if (counter % 50)" inside FixedUpdate will be true once in every second.

    -Juha
     
  4. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually, no, FixedUpdate is 60 per second by default, and if you change the fixed timestep in the time manager, then it's something else (.01 makes it 120 per second, for example). Plus it's not a good idea to rely on it being precisely every 1/60 of a second, since it might fire several times in a row if Update() takes too long, in order to keep the number of FixedUpdates to 60 per second.

    Another possibility in regards to the original question (might want to be more specific ;) ) is using Time.time or Time.realtimeSinceStartup.

    --Eric
     
  5. shawn

    shawn

    Unity Technologies

    Joined:
    Aug 4, 2007
    Posts:
    552
    This is a feature that the dreaded Virtools has which I agree would be really nice to see. Best place to see the benefits is making a realistically timed footstep sound. Lets say you have a walk cycle animation. You could set a specific frame of the animation to make an event call. In this case it could call a function that made a footstep sound. Unfortunately, I don't believe Unity is capable of this, yet... I would really like to see this kind of event callback for both Animations and Audio.

    At least that is what I think the original poster was looking for.
     
  6. JFo

    JFo

    Joined:
    Dec 9, 2007
    Posts:
    217
    Thanks Eric and Shawn for clearing this out!

    I've been testing audio syncing using FixedUpdate and it appeared to do the job. But it seesms my test scene was newer missing a frame in actual Update, so I got the false impression of thing working well ..

    It looks like the correct audio syncing (in high resolution) would then require an external plugin?

    -Juha
     
  7. Eric5h5

    Eric5h5

    Volunteer Moderator Moderator

    Joined:
    Jul 19, 2006
    Posts:
    32,401
    Actually, just out of curiosity, I tried this with the fixed timestep at the default .02:

    Code (csharp):
    1. var foo = 0;
    2.  
    3. function FixedUpdate() {
    4.     foo++;
    5. }
    6.  
    7. function Update() {
    8.     if (Time.time > 10.0) {print (foo);}
    9. }
    And the first number printed is 501. Looks like it's 50fps by default after all! :) The number I've always seen referenced is 60, and I never needed to know for sure, so that's what I was taking for granted all this time.... Although 50fps makes more sense anyway. Thanks for that! FixedUpdate can still fire several times in a row, however. ;)

    --Eric
     
  8. seefeldt81

    seefeldt81

    Joined:
    Dec 7, 2007
    Posts:
    33
    thanks everyone for the suggestions they all helped allot now I know the direction to go in. I'm making a cut scene and want it to end and load level at a specific point in the time line. Sorry I wasn't very specific I was in a rush.