- Home /
Question by
Qasim97 · Mar 14, 2017 at 09:36 AM ·
shaderplayer movementbutton trigger events
Add slippery player movement to button controls?
Hi, I have a game where my character moves, when i added the keyboard controls i made it so that the movement felt slippery. I now added buttons on screen for mobile although since i have added the PointerUp/Down script the movement isn't slippery anymore. I realised this is because that uses a bool to see whether the button is being pressed and when the button isn't pressed the movement is false and doesn't move a little further after pressing the button.
I really couldn't think of a way to do this and I was wondering if anybody else would have an idea. Thanks in advance and here is the code.
void Update () {
//Slippery movement with keyboard controls.
float z = Input.GetAxis ("Vertical") * Time.deltaTime * moveSpeed;
transform.Translate (0, 0, z);
//Using the buttons to move.
if (isUpPressed) {
print ("PRESSED");
transform.Translate (0, 0, (Time.deltaTime*moveSpeed));
}
if (isDownPressed) {
transform.Translate (0, 0, -(Time.deltaTime*moveSpeed));
}
}
public void onPointerDownUpButton(){
isUpPressed = true;
}
public void onPointerUpUpButton(){
isUpPressed = false;
}
public void onPointerDownDownButton(){
isDownPressed = true;
}
public void onPointerUpDownButton(){
isDownPressed = false;
}
Comment