コード例 #1
0
    void Update()
    {
        //mobile controls. Touch screens are too different to use fake mouse controls
        if (gameController.isPaused)
        {
            return;
        }
        if (Application.isMobilePlatform || splitter.mobileDebugging)
        {
            bool isNotTouching = true;
            foreach (Touch poke in Input.touches)
            {
                //first check if it's on the boxcollider 2D
                Vector3 wp       = Camera.main.ScreenToWorldPoint(poke.position);
                Vector2 touchPos = new Vector2(wp.x, wp.y);
                if (poke.fingerId == trackingID)
                {
                    //activate if the y position is too high
                    if (touchPos.y > 0.1f)
                    {
                        if (isReady)
                        {
                            switch (spellColor)
                            {
                            case "Red":
                                spellHandler.Redspell();
                                break;

                            case "Orange":
                                spellHandler.Orangespell();
                                break;

                            case "Yellow":
                                spellHandler.Yellowspell();
                                break;

                            case "Green":
                                spellHandler.Greenspell();
                                break;

                            case "Blue":
                                spellHandler.Bluespell();
                                break;

                            case "Purple":
                                spellHandler.Purplespell();
                                break;

                            case "Cyan":
                                spellHandler.Cyanspell();
                                break;

                            case "White":
                                spellHandler.Whitespell();
                                break;
                            }
                            isReady         = false;
                            isTransitioning = true;
                            startTime       = Time.time;
                        }
                        trackingID = -1;
                    }
                    else
                    {
                        //if the touchphase has ended, reset position
                        if (poke.phase == TouchPhase.Ended)
                        {
                            trackingID         = -1;
                            transform.position = activePos;
                            isNotTouching      = true;
                        }
                        else
                        {
                            transform.position = new Vector3(transform.position.x, touchPos.y, transform.position.z);
                        }
                    }
                }
                if (GetComponent <Collider2D>() == Physics2D.OverlapPoint(touchPos))
                {
                    isNotTouching = false;
                    //now check stage of the touch. If it's just happened, display the explination popup
                    if (poke.phase == TouchPhase.Began)
                    {
                        //popup the explination
                        splitter.setState("canShoot", false);
                        DescCanvas.GetComponent <Spell_Descriptions> ().display(spellColor);
                        trackingID = poke.fingerId;
                    }
                }
            }
            if (wasTouching && isNotTouching)
            {
                //hide popup
                splitter.setState("canShoot", true);
                DescCanvas.GetComponent <Spell_Descriptions> ().hide();
            }

            wasTouching = !isNotTouching;
        }
    }