x


increase speed when timer reaches zero

hi, i am making an endless runner and i need to increase the speed of certain gameobjects when the timer reaches 0. im using the following script. The timer and movement work fine but speed changes for only a fraction of a second.

movement.js

 // Building movement
 
 static var speed;
 
 speed = -10;
 
 function Update () {
 
 var x = Time.deltaTime * speed;
 
 transform.Translate(x, 0, 0);
 
 }

and this is the countdown timer

countdowntimer.js

 private var startTime;
 private var restSeconds : int;
 private var roundedRestSeconds : int;
 private var displaySeconds : int;
 private var displayMinutes : int;
 
 var countDownSeconds : int;
 
 function Awake() 
 {    
     Reset();
 }
 
 function Reset()
 {
     startTime = Time.time;
 }
 
 function OnGUI () {
     //make sure that your time is based on when this script was first called
     //instead of when your game started
     var guiTime = Time.time - startTime;
 
     restSeconds = countDownSeconds - (guiTime);
 
     //display messages or whatever here -->do stuff based on your timer
     
     
     if (restSeconds == 0) {
         movement.speed-=5;
         Reset();
     }
 
     //display the timer
     roundedRestSeconds = Mathf.CeilToInt(restSeconds);
     displaySeconds = roundedRestSeconds % 60;
     displayMinutes = roundedRestSeconds / 60; 
 
     text = String.Format ("{0:00}:{1:00}", displayMinutes, displaySeconds); 
     GUI.Label (Rect (400, 25, 100, 30), text);
 }

please help. im pretty new to coding. Thanks

more ▼

asked May 31, 2012 at 06:12 AM

zico_mahilary gravatar image

zico_mahilary
154 25 34 36

Hmm looking through this, it all looks ok. If you ever come to points like this and all seems well. You can use Debug.Log("Message Here");. Put this line of code before and after execution spots you find suspicious to be causing issues. You can put in variables in there too so you can track what an integer has been changed to, like in your instance. This can help you rule out which line of code is failing to do what you are wanting.

May 31, 2012 at 07:33 AM GC1983

thanks for the info..

as you said "You can put in variables in there too so you can track what an integer has been changed to, like in your instance."

could you tell me how to do that. i would like to track the variable "speed" from "movement.js"

i looked up script reference but couldn't figure it out.

May 31, 2012 at 09:02 AM zico_mahilary

thanks a lot.. that solved the problem

all i had to do was declare the variable speed in countdowntimer.js and increment it there. then call it in movement .js

cheers

May 31, 2012 at 09:53 AM zico_mahilary

Hey - could you possibly post that last as an answer - then mark it as answered? Just closes off the question and people won't keep looking at it :)

May 31, 2012 at 10:02 AM whydoidoit

You can Debug.Log(someVariable.ToString()) or you could use the debugger http://unity3d.com/support/documentation/Manual/Debugger.html

May 31, 2012 at 09:37 AM whydoidoit
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You can Debug.Log(someVariable.ToString()) or you could use the debugger http://unity3d.com/support/documentation/Manual/Debugger.html

thanks a lot.. that solved the problem

all i had to do was declare the variable speed in countdowntimer.js and increment it there. then call it in movement .js

cheers

more ▼

answered May 31, 2012 at 10:10 AM

zico_mahilary gravatar image

zico_mahilary
154 25 34 36

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

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

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x571
x12

asked: May 31, 2012 at 06:12 AM

Seen: 746 times

Last Updated: May 31, 2012 at 10:13 AM