Search code examples
c#unity-game-enginearcore

Display Debug.drawLine() with ArCore


I'm trying to display a Line between two objects that I instantiate with ARCore. I don't have any problem in virtual environnement (without ARCORE) but when I want to adapt it for augmented reality, my markers display but not my Line. I'm struggling to debug it too as I don't have any log with the phone...

my code :

  // Raycast against the location the player touched to search for planes.
        TrackableHit hit;
        TrackableHitFlags raycastFilter = TrackableHitFlags.PlaneWithinBounds | TrackableHitFlags.PlaneWithinPolygon;

        if (Session.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
        {
            if (instantiationState == true) //instantiate greencube on click
            {
                Destroy(landmarkEven);
                andyObject = Instantiate(Resources.Load("CubeA", typeof(GameObject)), (hit.Pose.position + new Vector3(0, 1, 0)), hit.Pose.rotation) as GameObject;
                landmarkEven = andyObject;
                instantiationState = false;

            }
            else //instantiate redcube on click
            {
                Destroy(landmarkOdd);
                andyObject = Instantiate(Resources.Load("CubeB", typeof(GameObject)), (hit.Pose.position + new Vector3(0, 1, 0)), hit.Pose.rotation) as GameObject;
                landmarkOdd = andyObject;
                instantiationState = true;
            }

            // Create an anchor to allow ARCore to track the hitpoint as understanding of the physical
            // world evolves.
            var anchor = hit.Trackable.CreateAnchor(hit.Pose);

            // Andy should look at the camera but still be flush with the plane.
            andyObject.transform.LookAt(FirstPersonCamera.transform);
            andyObject.transform.rotation = Quaternion.Euler(0.0f,
                andyObject.transform.rotation.eulerAngles.y, andyObject.transform.rotation.z);

            // Make Andy model a child of the anchor.
            andyObject.transform.parent = anchor.transform;
        }
        if (landmarkEven != null && landmarkOdd != null)
        {
            Debug.DrawLine(landmarkEven.transform.position, landmarkOdd.transform.position, Color.green);
        }

The main purpose of this is to instantiate a third object base on the direction of that line. If anyone see something strange with my code, or have any idea to realise it in another way.


Solution

  • If the issue is on the phone, then that's because Debug.DrawLine is for debugging in the Unity Editor playmode only.