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

Timer wont work

Discussion in 'Scripting' started by aixaix, Jan 10, 2014.

  1. aixaix

    aixaix

    Joined:
    May 7, 2010
    Posts:
    523
    I took this script form my older project... (cause I'm lazy to rewrite things :D) but the script doesn't seem to work... the time.deltaTime part doesn't start coutning... But it works in my other project...

    Code (csharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class Startuplogo : MonoBehaviour {
    5.     public Light sLight;
    6.     public AudioClip startupSound;
    7.     public float SceneLength;
    8.     public float curTime;
    9.    
    10.     void Awake() {
    11.         SceneLength = startupSound.length;
    12.         audio.PlayOneShot(startupSound);
    13.     }
    14.    
    15.     public void Update() {
    16.         curTime += Time.deltaTime;
    17.        
    18.         if(curTime <= SceneLength) {
    19.             sLight.light.intensity = curTime;
    20.         }
    21.        
    22.         else if(curTime >= SceneLength) {
    23.             Application.LoadLevel(1);
    24.         }
    25.        
    26.         else {
    27.             return;
    28.         }
    29.     }
    30. }
     
  2. Duney

    Duney

    Joined:
    Aug 19, 2013
    Posts:
    170
    Not 100% sure, but because your doing a += it may be worth declaring the curTime at the start:

    Code (csharp):
    1. public float curTime = 0.0f
     
  3. _Nick

    _Nick

    Joined:
    Jun 29, 2013
    Posts:
    30
    I just quickly placed it in my project, and it worked perfectly fine. Have you made sure to attach it to an object, link the sound and light objects to it? I know it's trivial questions, but the script works perfectly fine as far as I'm aware!
     
  4. aixaix

    aixaix

    Joined:
    May 7, 2010
    Posts:
    523
    Yeah, I did everything needed (twice), But I'm starting to think that there's something in the project itself that's causing this problem...
    Ok, I'm gonna look further into it later...
     
  5. Sildaekar

    Sildaekar

    Joined:
    Jul 8, 2013
    Posts:
    95
    Are you getting any errors or warnings?
     
  6. aixaix

    aixaix

    Joined:
    May 7, 2010
    Posts:
    523
    Nah, fixed it... Turns out, I had Project Settings > Time > Timescale set to 0 :D