SchdowNVIDIA
SchdowNVIDIA

Reputation: 65

How can i make in Unity Left-Right Touch Controls?

I'm trying to make simple left-right controls in Unity but without success... I want to "split the screen" into two areas like the picture below so when you press at the right half the character goes right left half... I hope someone can help me.

It should work like that: How I want it

Upvotes: 0

Views: 2724

Answers (2)

Prodian
Prodian

Reputation: 71

You can add 2 huge buttons, make buttons color alpha 0, remove texts of buttons. IT is the easiest way I think. Anchors can help you to make auto-resolution for it.

Upvotes: 0

George Fabish
George Fabish

Reputation: 439

This depends on what platform you are targeting. You will want to get the screen width in pixels.

float screenWidth = Screen.width 

For Mobile you would do the following inside of the update method.

Touch touch = Input.GetTouch(0);
if(touch.position.x > (screenWidth/2))
 {
   //The User has touched on the right side of the screen
 }else
{
 //The user hase touched the left side of the screen 
}

To get this info for non mobile platform just use Input.mouseposition instead of Input.GetTouch. As far as if you also wanted to know how to move the player left and right that should be a different question. Because movement is based on a lot of different variables in Unity.(i.e 2D,3D, real world physics....etc). So if that is something you also want help with refer to this link that will explain some simple movement scripts

Upvotes: 2

Related Questions