예제 #1
0
    // Update is called once per frame
    void Update()
    {
        Touch touch;

        if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
        {
            return;
        }

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

        if (Frame.Raycast(touch.position.x, touch.position.y, raycastFilter, out hit))
        {
            if (SetupState == SetupStates.FindFloor)
            {
                _suggestedFloorHeight = hit.Pose.position.y;

                SwitchState(SetupStates.ConfirmFloor);
            }
            else if (SetupState == SetupStates.AddObstacles)
            {
                if (hit.Trackable is DetectedPlane)
                {
                    DetectedPlane plane = hit.Trackable as DetectedPlane;

                    GameObject go = Instantiate(ObstaclePrefab, hit.Pose.position, hit.Pose.rotation, PlayfieldObjects);

                    ObstacleController controller = go.GetComponent <ObstacleController>();
                    controller.Setup(plane, _suggestedFloorHeight);
                    _renderers.Add(controller.GetRenderer());
                }
            }
        }
    }