- Home /
Problem with guiTexture dpad
I'm making d-pad for my unity android game. I also have problem with script that controll this d-pad. Its working good , but If I move my touch from the button arrea, its still clicked. how to repair it ? I wanna to click 2 buttons (multitouch) in the same time, example Up and Left, then object should go diagonally. Any idea?
Greetings.
using UnityEngine; using System.Collections;
public class ArrowControll : MonoBehaviour {
public GUITexture guiLeft; public GUITexture guiRight; public GUITexture guiUp; public GUITexture guiDown; public GUITexture guiLeftUp; public GUITexture guiRightUp; public GUITexture guiLeftDown; public GUITexture guiRightDown;
public Vector2 direction;
void Update () {
foreach(Touch t in Input.touches)
{
if (guiLeft.HitTest(t.position) ) {
print(guiLeft.);
direction = new Vector2(0f, -1f);
}
if (guiRight.HitTest(t.position)) {
direction = new Vector2(0f, 1f);
}
if (guiUp.HitTest(t.position)) {
direction = new Vector2(1f, 0f);
}
if (guiDown.HitTest(t.position)) {
direction = new Vector2(-1f, 0f);
}
if (guiLeftUp.HitTest(t.position)) {
direction = new Vector2(1f, -1f);
}
if (guiRightUp.HitTest(t.position)) {
direction = new Vector2(1f, 1f);
}
if (guiLeftDown.HitTest(t.position)) {
direction = new Vector2(-1f, -1f);
}
if (guiRightDown.HitTest(t.position)) {
direction = new Vector2(-1f, 1f);
}
if (t.phase == TouchPhase.Canceled || t.phase == TouchPhase.Ended) {
// Stop all movement
direction = new Vector2(0f, 0f);
}
}
}
}
Your answer
Follow this Question
Related Questions
Multi touches problem 0 Answers
iPhone input multitouch 1 Answer
Multi touch for character movement on android[solved] 1 Answer
Problem with multi touch[solved] 0 Answers
How to stop second finger from manipulating position of gui joystick 1 Answer