Time wont reset
So, I am trying to set the script up so the timer resets either after pressing down a button, or when time runs out, but it is not resetting for either of them.
public float deccelerationTime = 3.0f;
void Start ()
{
deccelerationTime = Time.time;
}
void FixedUpdate ()
{
deccelerationTime = 3 - Time.time;
if (Input.GetKeyDown (KeyCode.S))
{
speed += gas * Time.deltaTime;
deccelerationTime = 3.0f;
}
else if (deccelerationTime == 0)
{
speed = speed / 2;
deccelerationTime = 3.0f;
}
Answer by toddisarockstar · Jan 19, 2016 at 02:58 PM
var deccelerationTime:float;
deccelerationTime = 3;
var gas:float;
gas=1;
function Update(){
speed = speed + gas * Time.deltaTime;
if (Input.GetKeyDown ("s")) {speed=0;}
if(speed>deccelerationTime){speed=0;}
}
is this what you are trying to do?
Not really. I want it so when I press S, I gain speed, and it resets the timer. If I dont press S, it halfs my speed and also resets the timer
Get$$anonymous$$eyDown happens on just the first frame the button is pushed Get$$anonymous$$ey will be true as long as the button is held down. does that help?
var deccelerationTime:float;
deccelerationTime = 3;
var gas:float;
gas=1;
var half:float;
half=2; var timer:float;
function Update(){
timer = timer * Time.deltaTime;
if (Input.Get$$anonymous$$eyDown ("s")) { timer=0;}
if (Input.Get$$anonymous$$ey ("s")) { speed = speed + gas * Time.deltaTime;}
else{speed=half;}
if(speed>deccelerationTime){speed=0;}
}
Not exactly what I was looking for. The S key does exactly what I want it to do, except, the timer I need has to either do 1 of 2 things
Reset back to 0 after hitting S -or- Reset back to 0 after three seconds have gone by.
The rest of the script I have figured out, this is the only thing I need really to finish up my small phone game.
Ill also try to explain what my game is doing
If S key is pressed down, +2 speed. Reset timer (Holding it down will do nothing. Will have to tap to add more speed)
If not hit, speed/2. Reset timer.
Your answer
Follow this Question
Related Questions
Need help with making disappearing platforms. Error CS1525 1 Answer
I make a timing score script in unity 2D, how i make high score of time?? Script is as follow: 1 Answer
HH:MM:SS game clock with modifiable start time error 1 Answer
Timer float not evaluating correctly when I check if it's less than another number 3 Answers
Timer only goes for .02 seconds 1 Answer