// Start is called before the first frame update
    void Start()
    {
        // Save a reference to the ARTapToPlaceObject component as our singleton instance
        Instance = this;

        arManager = FindObjectOfType <ARRaycastManager>();
        Debug.Log("arManager: " + arManager.ToString());

        arCamera = FindObjectOfType <ARSessionOrigin>().camera;
        Debug.Log("arCamera: " + arCamera.ToString());

        arSession = FindObjectOfType <ARSession>();
        Debug.Log("arSession: " + arSession.ToString());

        // Assign prefab in insepctor and place object with button click event
        if (placeObjectButton != null && objectToPlace != null)
        {
            placeObjectButton.onClick.AddListener(() =>
            {
                spawnedObject = Instantiate(objectToPlace, placementPose.position, placementPose.rotation);
            });
        }

        // Assign prefab in insepctor and place object with button click event
        if (destoryAllObjectButton != null)
        {
            destoryAllObjectButton.onClick.AddListener(() =>
            {
                SceneManager.LoadScene("ARScene");
                arSession.Reset();
            });
        }
    }
Beispiel #2
0
    // Start is called before the first frame update
    void Start()
    {
        // Save a reference to the ARTapToPlaceObject component as our singleton instance
        Instance = this;

        arManager = FindObjectOfType <ARRaycastManager>();
        Debug.Log("arManager: " + arManager.ToString());

        arCamera = FindObjectOfType <ARSessionOrigin>().camera;
        Debug.Log("arCamera: " + arCamera.ToString());

        arSession = FindObjectOfType <ARSession>();
        Debug.Log("arSession: " + arSession.ToString());

        // Assign prefab in insepctor and place object with button click event
        if (placeObjectButton != null && objectToPlace != null)
        {
            placeObjectButton.onClick.AddListener(() =>
            {
                dominos.Add(Instantiate(objectToPlace, placementPose.position, placementPose.rotation));
            });
        }

        // Assign prefab in insepctor and place object with button click event
        if (pushDominoButton != null && objectToPlace != null)
        {
            pushDominoButton.onClick.AddListener(() =>
            {
                if (dominos.Count > 0)
                {
                    GameObject firstDomino = dominos[0];
                    Debug.Log("firstDomino: " + firstDomino.ToString());

                    Vector3 direction = firstDomino.transform.position - transform.position;
                    //firstDomino.GetComponent<Rigidbody>().AddForceAtPosition(direction.normalized, transform.position);
                    Debug.Log("rigidbody: " + firstDomino.GetComponentInChildren <Rigidbody>());

                    var cameraForward = arCamera.GetComponent <Camera>().transform.forward;
                    var cameraBearing = new Vector3(cameraForward.x, 0, 0).normalized;
                    firstDomino.GetComponentInChildren <Rigidbody>().AddForce(cameraBearing * force);
                }
            });
        }

        // Assign prefab in insepctor and place object with button click event
        if (increaseForceButton != null)
        {
            increaseForceButton.onClick.AddListener(() =>
            {
                force         += 5;
                forceText.text = force.ToString();
            });
        }

        // Assign prefab in insepctor and place object with button click event
        if (decreaseForceButton != null)
        {
            decreaseForceButton.onClick.AddListener(() =>
            {
                force         -= 5;
                forceText.text = force.ToString();
            });
        }

        // Assign prefab in insepctor and place object with button click event
        if (destoryAllObjectButton != null)
        {
            destoryAllObjectButton.onClick.AddListener(() =>
            {
                Destroy(GameObject.FindWithTag("Dominos"));
                dominos.Clear();

                arSession.Reset();
            });
        }
    }