コード例 #1
0
    // Update is called once per frame
    void Update()
    {
        DebugText.text = "State: " + state;

        if (Variables.TriggerStop)
        {
            state = GameState.Drinking;
            Variables.TriggerStop = false;
        }

        if (Variables.TriggerGo)
        {
            state = GameState.None;
            StopCheckForPotentialMatches();
            hasBomb = true;
            Bomb.SetActive(true);
            Companion.StartSay("Wirf die Wasserbombe!", 5);
            Variables.TriggerGo = false;
        }

        if (ShowDebugInfo)
        {
            DebugText.text = DebugUtilities.GetArrayContents(shapes);
        }

        if (state == GameState.None)
        {
            //user has clicked or touched
            if (Input.GetMouseButtonDown(0))
            {
                //get the hit position
                var hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
                if (hit.collider != null) //we have a hit!!!
                {
                    hitGo = hit.collider.gameObject;
                    if (!hasBomb)
                    {
                        state = GameState.SelectionStarted;
                    }
                    else
                    {
                        StartCoroutine(FindMatchesAndCollapse(true));
                        hasBomb = false;
                    }
                }
            }
        }
        else if (state == GameState.SelectionStarted)
        {
            //user dragged
            if (Input.GetMouseButton(0))
            {
                var hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero);
                //we have a hit
                if (hit.collider != null && hitGo != hit.collider.gameObject)
                {
                    //user did a hit, no need to show him hints
                    StopCheckForPotentialMatches();

                    //if the two shapes are diagonally aligned (different row and column), just return
                    if (!Utilities.AreVerticalOrHorizontalNeighbors(hitGo.GetComponent <Shape>(),
                                                                    hit.collider.gameObject.GetComponent <Shape>()))
                    {
                        state = GameState.None;
                    }
                    else
                    {
                        state = GameState.Animating;
                        FixSortingLayer(hitGo, hit.collider.gameObject);
                        StartCoroutine(FindMatchesAndCollapse(hit));
                    }
                }
            }
        }
    }