Reputation: 469
I have made a script and attached it to main camera and the multi-touches are not being detected on any where on game scene. The console logs update at each frame but the input touches is not logged anywhere.None of the print statement runs inside the if statement. Any help would be appreciated.
void Update() {
print("update");
if (Input.touchCount > 0){
print("touch detected");
print(Input.touchCount);
print(Input.touchCount.toString());
}
}
Upvotes: 2
Views: 213
Reputation: 469
There is not only a "touch" word in touchable devices. There are several types of touch action such as single touch, multi-touch, swipe, pinch etc.
At first please delete the print function in update, it's unnecessary and silly action.
For a single touch, (as Hamza said) you can use Input.GetMouseButton
or Input.GetTouch
.
If you want to calculate the count of multi-touch, your usage is true. Try to attach script to another game object in scene. See this example for more on Unity's official page.
Upvotes: 3
Reputation: 1398
If you only have to get single touch then use Input.GetMouseButtonDown
. This will work on all platforms. Editor or device.
You can use it as,
void Update()
{
if (Input.GetMouseButtonDown(0))
{
Debug.Log("Screen touch detected");
}
if (Input.GetMouseButton(0))
{
Debug.Log("Screen touch and drag detected");
}
if (Input.GetMouseButtonUp(0))
{
Debug.Log("Screen touch lifted up");
}
}
Upvotes: 0