![]() ![]() Raycasts are typically treated as rays from the device or device camera, but you can use Raycast(Ray, List, TrackableType) to conduct a raycast using an arbitrary ray in world space coordinates instead of a screen-space point. Raycast hits are sorted by distance, so the first one will be the closest hit.Ĭonduct a raycast using an arbitrary ray and direction If (raycastManager.Raycast(touch.position, hits, trackableTypes)) Raycast against planes and feature points. ARCore providers currently only support PlaneEstimated, PlaneWithinBounds, PlaneWithinPolygon, FeaturePoint, Image, and Depth. Note: Not all TrackableTypes are supported by both ARCore and ARKit providers. ARRaycastManager supports all TrackableTypes. Place an object on a plane (floor or wall) using the plane’s full geometry where fast placement is critical, and the experience can tolerate unknown initial depth and scaleĪRRaycastManager.AddRaycast(Vector2 screenPoint, float estimatedDistance)Ĭall ARRaycastManager.Raycast(Vector2, List, TrackableType) to perform a raycast (hit-test). Works instantly, but pose and actual depth will change once ARCore is able to determine actual scene geometry ![]() Initially uses estimated depth provided by the app. Place an object on an arbitrary surface (not just on floors and walls)ĪRRaycastManager.Raycast(Vector2 screenPoint, List hitResults, TrackableType trackableTypes TrackableType.FeaturePoint) Relies on visual features around the point of a user tap to determine a point’s correct position and orientation ![]() Fallback for the Depth hit-testĪRRaycastManager.Raycast(Vector2 screenPoint, List hitResults, TrackableType trackableTypes TrackableType.PlaneWithinPolygon) Place an object on a plane (floor or wall) using the plane’s full geometry. Hits horizontal and/or vertical surfaces to determine a point’s correct depth and orientation Place a virtual object on an arbitrary surface (not just on floors and walls)ĪRRaycastManager.Raycast(Vector2 screenPoint, List hitResults, TrackableType trackableTypes TrackableType.Depth) Uses depth information from the entire scene to determine a point’s correct depth and orientation Hit result typesĪ hit-test can yield four different types of hit results, as shown by the following table. Correct placement ensures that the AR content is rendered at the appropriate (apparent) size. #2 answer should now work as long as a 2D collider is attached to it.Perform a raycast, or hit-test, to determine the correct placement of a 3D object in your scene. Delete the project, create a new Project and make sure you choose 2D this time. ![]() to the Sprite/Texture.ģ.If #2 did not work, then your project was created as a 3D instead of 2D. Since this is a 2D game, any collider you are using must end with 2D.For example, there is a Box Collider and there is a Box Collider 2D. Make sure that the Collider is covering the 2D Texture or Sprite by re-sizing the collider. RaycastHit2D cubeHit = Physics2D.Raycast(cubeRay, Vector2.zero) ĭebug.Log("We hit " + ) įor this to work, you must attach Collider2D to the 2D Texture or Sprite. Public void OnPointerDown(PointerEventData eventData)Ģ.Now if the GameObject you want to detect the touch with is just a 2D Texture or Sprite then use the code below: if (Input.GetMouseButtonDown(0)) Public void OnPointerClick(PointerEventData eventData) public class YourClass : MonoBehaviour,IPointerDownHandler,IPointerClickHandler To detect touch with Image/Canvas, you use have to derive from IPointerDownHandler or IPointerClickHandler then implement the functions from them. 1.If the Object you are trying to detect touch with is an Image/ Canvas, then this is not how to do this. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |