I'm working within Unity with the new UI 4.6 system.
Basically I have a very simple way of calculating the players movement (It only moves on the x axis). Due to this I'm only using "Horizontal" to get the movement at the moment.
What I need is a way to connect the value of the players movement to a slider so that when you drag it left it goes left and when you leave go it stops moving and the same for the right hand side.
I'm still new to programming and have looked all over to get a rough answer and I'm struggling.
Here are the two ways that I can move the player: The first is with velocity that I recently tried to do but then got lost as it will only send the player 1 way depending on the value of -1 or 1. I call the following statement in the FixedUpdate function.
public void Movement(float horizontalInput)
{
//Stores the velocity in a V3.
Vector3 moveVel = myBody.velocity;
//The x axis is the value passed intimes by movespeed.
moveVel.x = horizontalInput * moveSpeed;
//The value from the v3 is stored back into velocity.
myBody.velocity = moveVel;
}
public void StartMoving(float horizontalInput)
{
hozInput = horizontalInput;
}
Before trying to get a mobile type of movement I was simply using this:
Vector3 newPosition = transform.position;
newPosition.x += Input.GetAxis("Horizontal") * moveSpeed * Time.deltaTime;
transform.position = newPosition;
This was a very simple way to move the character but I'm unsure if I can assign it to the slider.
I know that the methods must be public void for an UI object to access them etc, it's just assigning the variables to the right places that I'm struggling with.
Thank you very much for your time.