- Home /
How to make 2 or more Objects to follow 2 or more fingers
So I'm trying to make a game where you need to control 2 objects, I managed to make obects to folow only one finger at time.
heres the code :
void Update () {
if (Input.touchCount == 1 && Input.GetTouch(0).phase == TouchPhase.Moved){
x = Input.GetTouch(0).position.x;
y = Input.GetTouch(0).position.y;
Vector3 move = Camera.main.ScreenToWorldPoint(new Vector3(x, y, 0));
transform.position = new Vector3(move.x, move.y);
}
if (Input.touchCount == 2 && Input.GetTouch(1).phase == TouchPhase.Moved){
x1 = Input.GetTouch(1).position.x;
y1 = Input.GetTouch(1).position.y;
Vector3 go = Camera.main.ScreenToWorldPoint(new Vector3(x1, y1, 0));
Obj.transform.position = new Vector3(go.x, go.y);
}
}
Please Help me :/ I allso would like to chech if my finger touched inside of object. :/
So I managed to make it work but now I don't know how can i check if my touch is inside of the object, I tried to use bounds.Contains but it does not work :/
Checking whether a point is inside of an object is a separate Q. There's a good chance it's already been asked/answered here.
Linking the Qs (getting a touch, then another touch, then checking inside) just makes it harder for other people to find later. For most problems, you can break them into parts this way.
Answer by YoungDeveloper · Aug 18, 2015 at 07:19 AM
Simply loop through touches, right now you working with first 0 only
Your answer
Follow this Question
Related Questions
Player not following touch after camera is rotated? 0 Answers
Camera rotation around player while following. 6 Answers
player following touch position 0 Answers
Touch Follow 3d. 1 Answer
Touch and drag an object 0 Answers