Beispiel #1
0
    private void grabBrick()
    {
        // Check if flystick is inside a brick
        GameObject[] bricks       = GameObject.FindGameObjectsWithTag("Brick");
        GameObject   selectedItem = null;

        foreach (GameObject brick in bricks)
        {
            if (brick.GetComponent <Collider>().bounds.Contains(flyStickInteraction.transform.position))
            {
                selectedItem = brick;
                break;
            }
        }

        // Check if flystick points on a brick
        if (selectedItem == null)
        {
            flyStickInteraction.sendRayForBlocks();
            selectedItem = flyStickInteraction.SelectedPart;
        }

        if (selectedItem)
        {
            interactingItem = selectedItem.GetComponent <InteractableItem>();
            if (interactingItem)
            {
                GameObject towerObject = GameObject.Find("DynamicTower");
                if (towerObject)
                {
                    TowerInteractivity tower = towerObject.GetComponent <TowerInteractivity>();

                    if (interactingItem.name.Contains(TowerInteractivity.MaxRow.ToString()) && interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        //return;
                    }
                    if (interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        if (tower.FirstSelected == null)
                        {
                            tower.select(interactingItem.transform.gameObject);
                            Debug.Log("select: " + interactingItem.transform.gameObject.name);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                if (interactingItem.isInteracting())
                {
                    interactingItem.EndInteraction(flyStickInteraction);
                    interactingItem = null;
                    Debug.Log("endInteraction");
                }
                interactingItem.BeginInteraction(flyStickInteraction);
            }
        }
    }
Beispiel #2
0
    private void Update()
    {
        if (enable)
        {
            if (InputSynchronizer.GetKeyDown("space"))
            {
                float minDistance = float.MaxValue;

                float distance;
                foreach (InteractableItem item in objectsHoveringOver)
                {
                    distance = (item.transform.position - transform.position).sqrMagnitude;
                    if (distance < minDistance)
                    {
                        minDistance = distance;
                        closestItem = item;
                    }
                }

                interactingItem = closestItem;
                closestItem     = null;

                GameObject towerObject = GameObject.Find("DynamicTower");
                if (towerObject != null && interactingItem != null)
                {
                    TowerInteractivity tower = towerObject.GetComponent <TowerInteractivity>();

                    if (interactingItem.name.Contains(TowerInteractivity.MaxRow.ToString()) && interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        return;
                    }
                    if (interactingItem.GetComponent <Renderer>().material.color != Color.green)
                    {
                        if (tower.FirstSelected == null)
                        {
                            tower.select(interactingItem.transform.gameObject);
                        }
                        else
                        {
                            return;
                        }
                    }
                }
                if (interactingItem)
                {
                    if (interactingItem.isInteracting())
                    {
                        interactingItem.EndInteraction(this);
                    }
                    interactingItem.BeginInteraction(this);
                }
            }
            if (InputSynchronizer.GetKeyUp("space") && interactingItem != null)
            {
                interactingItem.EndInteraction(this);
            }
        }
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        if (controller == null)
        {
            Debug.Log("Controller not initialized");
            return;
        }

        gripButtonDown    = controller.GetPressDown(gripButtonId);
        gripButtonUp      = controller.GetPressUp(gripButtonId);
        gripButtonPressed = controller.GetPress(gripButtonId);

        triggerButtonDown    = controller.GetPressDown(triggerButtonId);
        triggerButtonUp      = controller.GetPressUp(triggerButtonId);
        triggerButtonPressed = controller.GetPress(triggerButtonId);

        trackpadButtonDown    = controller.GetPressDown(trackpadButtonId);
        trackpadButtonUp      = controller.GetPressUp(trackpadButtonId);
        trackpadButtonPressed = controller.GetPress(trackpadButtonId);

        if (gripButtonDown)
        {
        }
        if (trackpadButtonUp)
        {
            GameObject.Find("Button_StartRecord").GetComponent <Button>().onClick.Invoke();
            pressedRecord = true;
        }
        if (triggerButtonDown)
        {
            // Debug.Log("triggerbutton was just pressed");
            if (pointer)
            {
                pointer.PulledTrigger();
            }
        }

        if (triggerButtonUp)
        {
            //  Debug.Log("triggerbutton was just unpressed");
        }


        if (triggerButtonDown)
        {
            float minDistance = float.MaxValue;

            float distance;

            foreach (InteractableItem item in objectsHoveringOver)
            {
                distance = (item.transform.position - transform.position).sqrMagnitude;     // sqr because it could also be negative
                if (distance < minDistance)
                {
                    minDistance = distance;
                    closestItem = item;
                }
            }

            interactingItem = closestItem;
            closestItem     = null;

            if (interactingItem)
            {
                if (interactingItem.isInteracting())     // this shouldn't happen that often...
                {
                    interactingItem.EndInteraction(this);
                }

                interactingItem.BeginInteraction(this);
            }
        }


        if (triggerButtonUp && interactingItem != null)
        {
            interactingItem.EndInteraction(this);
        }
    }
    //replace Update method in your class with this one
    void Update()
    {
        //if mouse button (left hand side) pressed instantiate a raycast
        Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
        RaycastHit hit;

        bool bHit = Physics.Raycast(ray, out hit);

        if (bHit)
        {
            if (hit.collider.gameObject.transform.parent)
            {
                if (hit.collider.gameObject.transform.parent.name == "MenuButton(Clone)")
                {
                    hit.collider.gameObject.GetComponent <MenuButtonScript>().coliding = true;
                }
                else if (hit.collider.gameObject.transform.parent.name == "DialogButton(Clone)")
                {
                    if (hit.collider.gameObject.GetComponent <DialogButtonScript>() != null)
                    {
                        hit.collider.gameObject.GetComponent <DialogButtonScript>().coliding = true;
                    }
                }
                else if (hit.collider.gameObject.transform.parent.name == "FinalScoreButton")
                {
                    hit.collider.gameObject.GetComponent <MenuButtonScript>().coliding = true;
                }
            }
        }

        if (Input.GetMouseButtonUp(0) && interactingItem != null)
        {
            Debug.Log(" up and not interacting ");
            interactingItem.EndMouseInteraction(this);
            interactingItem = null;
        }
        else if (Input.GetMouseButtonDown(0))
        {
            //create a ray cast and set it to the mouses cursor position in game
            ray = Camera.main.ScreenPointToRay(Input.mousePosition);


            bHit = Physics.Raycast(ray, out hit);
            if (bHit)
            {
                if (hit.collider.gameObject.transform.parent)
                {
                    if (hit.collider.gameObject.transform.parent.name == "MenuButton(Clone)")
                    {
                        hit.collider.gameObject.GetComponent <MenuButtonScript>().coliding = true;
                        hit.collider.gameObject.GetComponent <MenuButtonScript>().click    = true;
                    }


                    else if (hit.collider.gameObject.transform.parent.name == "DialogButton(Clone)")
                    {
                        Debug.Log("dialog buttons");
                        hit.collider.gameObject.GetComponent <DialogButtonScript>().coliding = true;
                        hit.collider.gameObject.GetComponent <DialogButtonScript>().click    = true;
                    }
                    else if (hit.collider.gameObject.transform.parent.name == "FinalScoreButton")
                    {
                        hit.collider.gameObject.GetComponent <MenuButtonScript>().coliding = true;
                        hit.collider.gameObject.GetComponent <MenuButtonScript>().click    = true;
                    }
                }
                if (hit.collider.gameObject.GetComponent <InteractableItem>() != null)
                {
                    interactingItem = hit.collider.gameObject.GetComponent <InteractableItem>();

                    Debug.Log("interacting " + interactingItem.isInteracting());
                    if (!interactingItem.isInteracting()) // this shouldn't happen that often...
                    {
                        interactingItem.BeginMouseInteraction(this);
                    }
                }
                else if (hit.collider.gameObject != null)
                {
                    Debug.Log("hit this object " + hit.collider.gameObject.name);
                }
            }
        }
        if (Input.GetKeyDown("a"))
        {
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Transform>().Translate(-0.1f, 0, 0);
        }
        else if (Input.GetKeyDown("d"))
        {
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Transform>().Translate(0.1f, 0, 0);
        }
    }