- Home /
Question by
MajdHamada · Apr 27, 2015 at 12:44 PM ·
unity 5touchjoystickjava
Touch JoyStick problem - JavaScript!!
Hi ..... i am trying to make Touch Joystick and it works fine ...
But ... when i add another touch button the joystick follow the other finger Position
How to chose which Touch My joystick Follow ... in Java ..
Thank you :)
untitledqwe.jpg
(313.7 kB)
Comment
It is mul$$anonymous$$ch, so you needed to use Touch.fingerId of your touches.
I cant say that it 100% works, but I wonder that can help you at your research. Im using also Input.GetTouch
public var touchNumber : int;
function Update () {
for (var i = 0; i < Input.touchCount; i++){
var ray = Camera.main.ScreenPointToRay (Input.GetTouch(i).position);
if (Physics.Raycast (ray, hit, 10)){
if (hit.collider.tag == "Joystick"){
touchNumber = i;
}
}
var ray2 = Camera.main.ScreenPointToRay (Input.GetTouch(touchNumber).position);
if (Input.touchCount > 0 &&
Input.GetTouch(touchNumber).phase == TouchPhase.$$anonymous$$oved && Physics.Raycast (ray2, hit, 10)){
//do something
}
else if (Input.GetTouch(touchNumber).phase == TouchPhase.Canceled || Input.GetTouch(touchNumber).phase == TouchPhase.Ended) {
touchNumber = -1;
//do something
}}
Thank you very much ..... i change the script but you give me the start idea ....this is my script ..
for (var i = 0; i < Input.touchCount; i++){
touchNumber = i;
if (Input.touchCount > 0 &&
Input.GetTouch(touchNumber).phase == TouchPhase.$$anonymous$$oved ){
if( Input.GetTouch(i).position.x>-230&&Input.GetTouch(i).position.x<310){
JoyStickImage.transform.position.x = Input.GetTouch(i).position.x;
JoyStickImage.transform.position.y = Input.GetTouch(i).position.y;
}}
if (Input.GetTouch(touchNumber).phase == TouchPhase.Canceled || Input.GetTouch(touchNumber).phase == TouchPhase.Ended) {
touchNumber = -1;
JoyStickImage.transform.position.x = 0;
JoyStickImage.transform.position.y = 0;
}}