Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //drop box into the world
        if (boxToggle.IsInteractable() && boxToggle.isOn)
        {
            if (Input.GetMouseButtonDown(0))
            {
                // Check if the mouse was clicked over a UI element
                //if (!EventSystem.current.IsPointerOverGameObject())
                //{
                if (IsPointerOverUIElement() == false)
                {
                    //Debug.Log("Dropped a box");
                    mouseDownPos = Input.mousePosition;
                }
            }


            if (Input.GetMouseButtonUp(0))
            {
                //Debug.Log("time: " + (Time.time - timeOfLastDrop).ToString());
                //Vector3.SqrMagnitude(a - b) < 0.0001
                //if (mouseDownPos == Input.mousePosition && (Time.time - timeOfLastDrop) > 2f)
                if (Vector3.SqrMagnitude(mouseDownPos - Input.mousePosition) < 20f && (Time.time - timeOfLastDrop) > 2f)
                {
                    timeOfLastDrop = Time.time;
                    Vector3 worldPos     = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    Vector3 worldTopPos  = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width, Screen.height, 0f));
                    Vector3 gridWorldPos = GridWorld.GetGridPointCenter(worldPos);


                    //SoundManager.instance.PlaySingle(SoundManager.instance.drop, 0.2f);

                    //trigger box stacking tutorial in Equity

                    GameObject instantiatedBox = Instantiate(boxPrefab, new Vector3(gridWorldPos.x, worldTopPos.y, boxPrefab.transform.position.z), boxPrefab.transform.rotation) as GameObject;
                    instantiatedBox.transform.SetParent(GameManager2.instance.GetCurrentRuntimeObjsParent());
                    HeartCounter.Instance.DecrementBoxHearts();

                    if (GameManager2.instance.fsm.CurrentStateMap.state.ToString() == GameManager2.States.Equality.ToString())
                    {
                        if (GameManager2.instance.clickTutorialUI.activeInHierarchy)
                        {
                            GameManager2.instance.clickTutorialUI.SetActive(false);
                        }
                    }

                    //if (GameManager2.instance.fsm.CurrentStateMap.state.ToString() == GameManager2.States.Equity.ToString() && GameManager2.instance.equity_ShortC.myBoxes.Count == 1)
                    //{
                    //    if (GameManager2.instance.wideTutorialUI.activeInHierarchy)
                    //    {
                    //        GameManager2.instance.wideTutorialUI.SetActive(false);
                    //    }
                    //}
                }
            }
        }
    }