- Home /
android touch input
hey all,
how can i make it so that a touch area is constrained eg. if you touch the bottom right it will look around, if you touch the bottom left it will move the player, top right will execute a shoot command and top left will aim down sight.
how can i do this? please no linking to the android.input page it does not explain anything about how to do this
Answer by gregzo · Apr 14, 2012 at 01:23 PM
var cornerSize : int;
function Update()
{
for(var i:int=0;i<Input.touchCount;i++)
{
if(Input.GetTouch(i).phase==TouchPhase.Began)
{
TouchInCornerEval(Input.GetTouch(i).position);
}
}
}
function TouchInCornerEval(pos : Vector2)
{
if(pos.x<cornerSize&&pos.y<cornerSize)
{
print("touch in bottom left corner);
}
else if(pos.x<cornerSize&&pos.y>Screen.height-cornerSize)
{
print("touch in upper left corner);
}
else
{
print("you get the idea!The other two are for you to do....);
}
}
Just added the TouchPhase check, which I had forgotten... Sorry if you've tried the script already!
Your answer
Follow this Question
Related Questions
Unity 2D Mobile Game Drawing Mechanic 0 Answers
Make an object move in the direction of touch 0 Answers
Touch and release type of controll in Unity (Android). How to make it? 0 Answers
Is touch began guaranteed? 0 Answers
SmoothDamp touch look iOS Android 1 Answer