- Home /
Unity 2d mobile movement
So I made a game where you could go up and down left or right. First a made four buttons - one for each direction and then I added Axis Touch Button Script from CrossPlatformInput package. Then I wrote this script and X direction worked nice but when I tried Y direction it didn't worked. I tried a lot of things but it didn't worked. Thanks for answers. Here is the script:
float directionX;
float directionY;
Rigidbody2D rb;
void Start(){
rb = GetComponent<Rigidbody2D>();
}
void Update(){
directionX = CrossPlatformInputManager.GetAxis("Horizontal");
rb.velocity = new Vector2(directionX * 50, 0);
}
Your answer
Follow this Question
Related Questions
2D Game, Character Slides off Slopes, Need to be Able to Walk on Them 1 Answer
Standing on player to follow his movement,Follow movement when standing on moving platform/player 1 Answer
Rigid Body Movement (Mobile Issue) 3 Answers
Rigidbody2D x velocity not moving unless placed in FixedUpdate 1 Answer
Maintaining Run on direction change (double tap using GetAxis) 0 Answers