- Home /
speed increase only when button is pressed(touch).
I want to increase object's speed only when the button is pressed(touched), it should come back to normal speed when the button is not pressed(touched).
transform.Translate(direction * Time.deltaTime * speed);
I tried
public void SpeedUp(){
speed * 10;
}
and added this to button. Speed is increasing when button is pressed but not coming back to normal when button is left.
are you using unity ui button on click event or costume script ?
yes, I am using unity UI OnClick event. I have added SpeedUp() function to the OnCLick event of button UI.
public void SpeedUp()
{
speed = speed * 10;
}
Answer by Ali-hatem · Aug 16, 2017 at 10:48 AM
remove the on click and add event trigger component to the button
in the event trigger add new event type and select PointerDown
again add new event type and select PointerUp
now you know the rest each event needs a public function one for pressing & other for releasing the same way you handle on click event.
Answer by unidad2pete · Aug 12, 2017 at 06:49 AM
if(Input.GetKey(KeyCode.Space))
{
speed = 10;
} else
{
speed = 1;
}
That's for keyboard, how to do it for Android and iOS. I have used button UI..
Hi, I want to ask the same question when i'm using UI button@unidad2pete . did you know how to do it ? @$$anonymous$$i4Chan
still trying to figure it out. If you find something before me please let me know.
This is what I have tried, this works to increase the speed of that object but on leaving the button the speed is not co$$anonymous$$g back to normal.
Your answer
Follow this Question
Related Questions
time out between 2 touches android 1 Answer
Stop shooting when I press a gui button 1 Answer
If you help me, i make you 3d object 1 Answer
Touch Button animation 0 Answers
Touch button to load scene, instead of touching anywhere on screen 1 Answer