- Home /
Having an issue with getting my touch controls working
I've been trying to add touch controls to my game, and am having a bit of a problem with movement on the horizontal axis. Here is the relevant code:
In Player Controller Script
public void Jump()
{
GetComponent<Rigidbody2D> ().velocity = new Vector2 (GetComponent<Rigidbody2D> ().velocity.x, jumpHeight);
}
public void Move(float moveInput)
{
GetComponent<Rigidbody2D> ().velocity = new Vector2 (moveSpeed * moveInput, GetComponent<Rigidbody2D> ().velocity.y);
}
In a separate Touch Controls Script
private PlayerController Player;
void Start () {
Player = FindObjectOfType<PlayerController> ();
}
public void LeftArrow()
{
Player.Move (-1);
}
public void RightArrow()
{
Player.Move (1);
}
public void UnpressedArrow()
{
Player.Move (0);
}
public void Jump()
{
Player.Jump ();
}
This is the Event Trigger for my Jump button (My jumping works)
This is the Event Trigger for my Move Left button, which is the same as my Move Right button but in reverse (Neither moving left nor right works)
I think it may have something to do with the Pointer Up that is on the horizontal movement buttons, but I am not sure and have no idea how to fix it if that is the problem. Any help is appreciated.
Your answer
Follow this Question
Related Questions
Touch and release type of controll in Unity (Android). How to make it? 0 Answers
Small question about converting from Android to iOS 1 Answer
Drag a ball to add force to a ball by touch screen 1 Answer
Raycast from player to touch point? 2 Answers
Control the camera with a half of the touch screen 0 Answers