ive set up my methods to work for a keyboard so for instance this calls my moving left method
if (Input.GetKey(KeyCode.LeftArrow))
{
movingLeft();
animationClips();
}
i want to call the same method from a ui button i use a bool when true it can move when false it cant and set these to my button in in the pointer up and pointer down to get continual movement something like this
public void MoveMeLeft()
{
moveLeft = true;
}
public void StopMeLeft()
{
moveLeft = false;
}
and then check them and move accordingly like this
if (moveLeft && !moveRight)
{
movingLeft();
animationClips();
}
if (moveRight && !moveLeft)
{
movingRight();
animationClips();
}
but this doesnt seem to work, if i add a debug.log(“player should be moving left”) in my moving left method it prints to the screen but no movement happens despite it being the same method im calling for the keyboard and it works fine, can any body tell me whats going on here?
heres my movingLeft method,
public void movingLeft()
{
moveHorizontal = Input.GetAxis("Horizontal");
Debug.Log("i should be moving left"); //this displays in the console when pressing keyboard or pressing the ui button
Vector3 movement = new Vector3(moveHorizontal, 0, 0);
playerRigidbody.AddForce(movement * speed);
if (moveHorizontal < 0)
{
jumpDirection = false;
moveDirection = false;
}
}
any and all suggestions welcome, many thanks