- Home /
why my game is not getting its normal speed back with this code?
void OnMouseDown () {
if(name == "SlowButton"){
PlaneMovement.GameSpeed = 0.5f;
}
if(name == "MediumButton"){
PlaneMovement.GameSpeed = 1f;
}
if(name == "FastButton"){
PlaneMovement.GameSpeed = 2f;
}
if(name == "VeryFastButton"){
PlaneMovement.GameSpeed = 3f;
}
Application.LoadLevel("game");
}
I enter with this code into the Next Scene and there i have a code for some extra Power like speedup while collision occurs for that the code is:
if(C.tag == "Dimond"){
Camera.main.GetComponent<StoneInitiate>().DimondList.Remove(C.gameObject);
Destroy (C.gameObject);
Camera.main.GetComponent<StoneInitiate>().StoneCounter+=20;
smooth = 4f;
SpeedUpTimer = 5f;
SpeedUp = true;
}
speedup code is:
PlaneMovement.GameSpeed = Mathf.Lerp (PlaneMovement.GameSpeed,smooth,Time.time);
if(SpeedUp){
SpeedUpTimer -= Time.deltaTime;
print(SpeedUpTimer);
if(SpeedUpTimer <= 0){
SpeedUp = false;
smooth = PlaneMovement.GameSpeed;
}
It Works Fine when collision occurs but smooth takes value 4f and It Doesn't get value form
PlaneMovement.GameSpeed
please help me for that I am new in Unity. Thanks in advance.
Comment
Answer by khenid · Aug 22, 2014 at 05:29 AM
I just Do this and it works..
float smooth;
float smooth1;
void Start () {
smooth = PlaneMovement.GameSpeed;
smooth1 = PlaneMovement.GameSpeed;
}
PlaneMovement.GameSpeed = Mathf.Lerp (PlaneMovement.GameSpeed,smooth,Time.deltaTime);
if(SpeedUp){
SpeedUpTimer -= Time.deltaTime;
if(SpeedUpTimer <= 0){
SpeedUp = false;
smooth = smooth1;
}
Your answer
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Trigger player movement on touch 1 Answer