Beispiel #1
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }


        if (controller.GetPressDown(triggerButton))
        {
            triggerDown = true;
        }
        if (controller.GetPressUp(triggerButton))
        {
            triggerDown = false;
        }
        if (controller.GetPressDown(menuButton))
        {
            AR.toggleAR();
        }
        if (controller.GetPressDown(triggerButton))
        {
            float minDistance = float.MaxValue;
            float distance;

            foreach (InteractableItem item in objectsHoveringOver)
            {
                if (item == null)
                {
                    objectsHoveringOver.Remove(item);
                }
                else
                {
                    distance = (item.transform.position - transform.position).sqrMagnitude;

                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        closestItem = item;
                    }
                }
            }
            interactingItem = closestItem;

            if (interactingItem)
            {
                if (interactingItem.IsInteracting())
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }

        if (controller.GetPress(triggerButton) && interactingItem != null)
        {
            if (controller.GetPressDown(gripButton) && interactingItem.GetComponent <ProductController>() != null)
            {
                interactingItem.EndInteraction(this);
                objectsHoveringOver.Remove(interactingItem);
                cart.fastAddToCart(interactingItem.GetComponent <ProductController>());
                interactingItem = null;
            }
        }

        if (controller.GetPressUp(triggerButton) && interactingItem != null)
        {
            if (ARobjGrabbed)
            {
                interactingItem.GetComponent <BoxCollider>().isTrigger = true;
                ARobjGrabbed = false;
            }
            interactingItem.EndInteraction(this);
            objectsHoveringOver.Remove(interactingItem);
            interactingItem = null;
        }


        if (controller.GetPressDown(gripButton))
        {
            if (AR.getActiveStatus())
            {
                AR.setWand(this);
                AR.gripButtonPressed(true);
            }
        }

        if (controller.GetPressUp(gripButton))
        {
            AR.gripButtonPressed(false);
        }
    }