- Home /
How to only get touch on specific object?
First I was trying to make 2 "buttons" work like right input and left input with GetMouseButtonDown, but since it doesn't support Multi Touch, decided to change to Touch Inputs.
I'm using this code (in the left button):
using UnityEngine;
using System.Collections;
public class TouchLeft : MonoBehaviour {
public GameObject projectile;
void Update() {
int i = 0;
while (i < Input.touchCount) {
if (Input.GetTouch(i).phase == TouchPhase.Began)
GameObject.Find ("GavielG_Charge").GetComponent<Platformer2DUserControl> ().h = -1;
else
GameObject.Find ("GavielG_Charge").GetComponent<Platformer2DUserControl> ().h = 0;
++i;
}
}
}
But using it makes all the screen touchable, anyone can help me make the script only set the button touchable?
Comment
You will have to Physics.Raycast() to see what object you are touching. Lots of Raycast() questions and examples on Unity Answers.
Your answer
Follow this Question
Related Questions
mobile programming questions 1 Answer
cant touch multiple objects on screen (c# , mobile) 0 Answers
Camera movement using touch input 0 Answers
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Ray Casting iOS 0 Answers