Touchscript - Get GameObject where a touch is given

Random discussions.

Touchscript - Get GameObject where a touch is given

Postby lifGwaethrakindo » Mon Jul 04, 2016 1:25 am

Hi. I am making a swipe script, but it is a swipe between two objects, so I have to detect that in both pressed and released gestures those objects were pressed. The problem is that I don't know the right method to get the GameObject once a gesture begins. I thought that I could do it getting the PressedGesture name (as a debugging), but it returns me a Swipe Controller name, so I am not getting the right GameObject name.

This is the code on which I tried to get the game object name:

private void pressedHandler(object sender, EventArgs e)
{
PressGesture gesture = sender as PressGesture;
TouchHit hit;
gesture.GetTargetHitResult (out hit);
startPos = hit.Point;

if(gesture.gameObject == this.swipePositions[0]) //Swipe Positions stores both GameObjects I mentioned fr the swipe...
{
Debug.Log ("Pressed on: " + gesture.gameObject.name + " at: " + startPos);
}
else
{
Debug.Log("Not even from the start...");
Debug.Log("This name is: " +gesture.gameObject.name); //Returns "Swipe Controller"
Debug.Log("The name should be: " +this.swipePositions[0].name); //Returns "Cube" (the actualo name of the object)
}
}

Thanks in advance.
lifGwaethrakindo
 
Posts: 2
Joined: Mon Jul 04, 2016 1:17 am

Re: Touchscript - Get GameObject where a touch is given

Postby lifGwaethrakindo » Mon Jul 04, 2016 4:00 am

Solved. Just like a physics raycast, in TouchScript the TouchHit GameObjects contains both RaycastHit and RaycastHit2D properties, so you just need to cast the respective case ray, then check its transform.gameObject.
lifGwaethrakindo
 
Posts: 2
Joined: Mon Jul 04, 2016 1:17 am

Re: Touchscript - Get GameObject where a touch is given

Postby sergi » Sat Oct 22, 2016 9:02 pm

Please, can you write the code you used?

Thanks you
sergi
 
Posts: 33
Joined: Mon Mar 02, 2015 3:17 pm


Return to General Discussion

Who is online

Users browsing this forum: No registered users and 1 guest