- Home /
This post has been wikified, any user with enough reputation can edit it.
Question by
ASECENAS · Feb 01, 2017 at 09:05 AM ·
multitouchtimers
Multiple touch timers
I cannot find a way to count the time of a touch of each of my individual objects.
The game start and create for example 2 objects... each object needs to be destroy on certain time when the object is touched, but some how it does´t respect me the time that has each object.
I detect the touches successfully but I don´t know how to put the time of each touch individually.
Code:
void Update ()
{
int nbTouches = Input.touchCount;
if (nbTouches > 0)
{
print(nbTouches + " touch(es) detected");
for (int i = 0; i < nbTouches; i++)
{
Touch touch = Input.GetTouch(i);
ray = Camera.main.ScreenPointToRay(touch.position);
print("Touch index " + touch.fingerId);
if (Physics.Raycast(ray, out hit, Mathf.Infinity))
{
if (touch.fingerId.Equals(i))
{
if (hit.collider.tag == "Circle")
{
touchTime = Time.time;
Debug.Log("TIME" + touchTime);
if (touchTime > holdTime)
{
touchTime = 0;
Debug.Log("It´s going to destroy the G.O." + touchTime);
Destroy(hit.collider.gameObject);
}
}
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Unity 2.6 Support Windows 7 multi-touch? 2 Answers
multi-touch woe, index out of bounds? 1 Answer
Multitouch and collision for android 0 Answers
Touch dont work 1 Answer
Disable multiple touches while dragging a gameObject 0 Answers