Move left/right and jump on 3 different functions
Hi. I'm having a bit of trouble splitting my moving script into 3 seperate functions. Can anyone help me to seperate them? I then want to assign each of them to a different button that i've got on screen. I know how to assign the functions, but i've been trying to seperate them for hours now and i can't get it to work.
Here's the script: if (Time.time - startTime < animationDuration) { controller.Move (Vector3.forward speed Time.deltaTime); return; }
moveVector = Vector3.zero;
if (controller.isGrounded)
{
verticalVelocity = -0.5f;
}
else
{
verticalVelocity -= gravity * Time.deltaTime;
}
//We want to check whether it is less than the deadZone instead of whether it's equal to zero
float input = Input.GetAxis("Horizontal");
if (Input.GetMouseButton (0) && Input.mousePosition.y < Screen.height/2)
input += Input.mousePosition.x * 2 / Screen.width - 1;
if(Mathf.Abs(input) > deadZone) {
if(!didChangeLastFrame) {
didChangeLastFrame = true; //Prevent overshooting lanes
laneNumber += Mathf.RoundToInt(Mathf.Sign(input));
if(laneNumber < 0) laneNumber = 0;
else if(laneNumber >= lanesCount) laneNumber = lanesCount - 1;
}
} else {
didChangeLastFrame = false;
//The user hasn't pressed a direction this frame, so allow changing directions next frame.
moveDirection = new Vector3(0, 0, Input.GetAxis("Vertical"));
moveDirection = transform.TransformDirection(moveDirection);
moveDirection *= speed;
if (Input.GetMouseButton (0) && Input.mousePosition.y > Screen.height / 2 && Time.time > jumpDelay)
if (controller.isGrounded) {
verticalVelocity = jumpPower;
anim.SetTrigger (jumpHash);
//speed = speed + 5.0f;
//jumpDelay = Time.time + 1.5f;
//StartCoroutine(speedInMidAir());
//print ("ADDED");
}
}
Vector3 pos = transform.position;
pos.x = Mathf.Lerp(pos.x, firstLaneXPos + laneDistance * laneNumber, Time.deltaTime * sideSpeed);
transform.position = pos;
moveDirection.y -= gravity * Time.deltaTime;
controller.Move (moveDirection * Time.deltaTime);
And I want a seperate function for moving left, for moving right and for jumping. So 3 altogether.
Before i had it setup so that when you click either side of the screen you go to that side. The top part of the screen was for jumping.
Also, the player is moving in 3 lanes if that's of relevance.
Thank you for any help in advance.