Beispiel #1
0
 void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.gameObject.name == "Player")
     {
         playerCombo.addCombo(20, "破除魔法");
         Destroy(gameObject);
         if (isBlue == true && statefulInspection.isStarPlatinum == false)
         {
             gameOver.Over();
         }
     }
 }
    // Update is called once per frame
    void Update()
    {
        test = getVelocityX();
#if UNITY_IOS || UNITY_ANDROID || UNITY_EDITOR //if current platform is mobile,
        bool flag1 = false;

#if UNITY_IOS || UNITY_ANDROID
        if (Input.touchCount > 0 && !playerMoving.isPlayerDashing)//判断是否有触摸信息
        {
            for (int i = 0; i < Input.touchCount; i++)
            {
                Touch touch = Input.touches[i];                                                                                                                    //将触摸信息传递给touch

                if (touch.phase == TouchPhase.Stationary || touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Ended) //touch.phase是触摸的相位信息,通过TouchPhase枚举中来确定当前的状态,Began:一个手指开始接触;Moved:一个手指发生了移动;Stationary:一个手指接触了屏幕但是没有发生移动;Ended:一个手指离开屏幕,也是最后的状态;Cnaceled:系统取消对触摸监听,如用户把屏幕放到他脸上或超过五个接触同时发生
                {
                    touchPosition = touch.position;                                                                                                                //获取触摸的位置信息,该坐标与屏幕坐标一致
                    if (touchPosition.x < screenWidth / 3)                                                                                                         //screenWidth在Start中已经赋值=>screenWidth = Screen.width
                    {
                        if (playerMoving.isPlayerJumped == false && GetComponent <Rigidbody2D>().velocity.y >= -0.5 * timeSpeed)
                        {
                            GetComponent <Rigidbody2D>().velocity = new Vector2(0, 8 * timeSpeed);
                            playerMoving.isPlayerJumped           = true;
                        }
                        if (playerMoving.isPlayerClimbing == false && playerMoving.isPlayerBlocked == true && (playerMoving.isPlayerJumped == true || GetComponent <Rigidbody2D>().velocity.y < -0.5 * timeSpeed))
                        {
                            if (playerMoving.isPlayerClimbing == false)
                            {
                                if (!playerMoving.isPlayerDown)
                                {
                                    playerCombo.addCombo(5, "攀爬墙壁");
                                }
                                playerMoving.isPlayerClimbing         = true;
                                playerMoving.isPlayerJumped           = true;
                                GetComponent <Rigidbody2D>().velocity = new Vector2(0, 8f * timeSpeed);
                            }
                        }
                    }
                    if (touchPosition.x > screenWidth * 2 / 3)//screenWidth在Start中已经赋值=>screenWidth = Screen.width;
                    {
                        if (touch.phase == TouchPhase.Stationary || Vector2.Distance(startPosition, touchPosition) < 50)
                        {
                            keyHoldTime++;
                        }
                        if (touch.phase == TouchPhase.Began)
                        {
                            startPosition = touchPosition;
                        }
                        if ((touch.phase == TouchPhase.Stationary || theWorldStart) && keyHoldTime >= 10)
                        {
                            cameraFollow.zoomIn();
                            flag1 = true;
                            if (Vector2.Distance(startPosition, touchPosition) > 50 && playerMoving.isPlayerDashed == false && startPosition.x < touchPosition.x)
                            {
                                Line();
                            }
                            else
                            {
                                DisableEffects();
                            }
                            if (!theWorldStart)
                            {
                                rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y * 0.05f);
                                theWorldStart        = true;
                            }
                            theWorldEnd = false;
                            timeSpeed   = 0.05f;
                            rigidbody2D.gravityScale = 0.0025f * gravity;
                        }
                        if (touch.phase == TouchPhase.Ended)
                        {
                            keyHoldTime = 0;
                            if (Vector2.Distance(startPosition, touchPosition) > 50 && playerMoving.isPlayerDashed == false && startPosition.x < touchPosition.x)
                            {
                                dash();
                            }
                            startPosition = Vector2.zero;
                        }
                    }
                }
            }
        }
#endif

#if UNITY_EDITOR
        if (Input.GetButton("Fire1") && !playerMoving.isPlayerDashing)
        {
            if (playerMoving.isPlayerJumped == false && GetComponent <Rigidbody2D>().velocity.y >= -0.5 * timeSpeed)
            {
                playerMoving.isPlayerDashed           = false;
                GetComponent <Rigidbody2D>().velocity = new Vector2(0, 8 * timeSpeed);
                playerMoving.isPlayerJumped           = true;
            }
        }
        if (Input.GetButton("Fire2") && !playerMoving.isPlayerDashing)
        {
            keyHoldTime++;
            if (keyHoldTime >= 10)
            {
                //Debug.Log("TimeStop");
                //if (Vector2.Distance(new Vector2(Input.mousePosition.x,Input.mousePosition.y) ,new Vector2(transform.position.x ,transform.position.y))>100)
                //{
                //    Line();    //显示指示线
                //}
                cameraFollow.zoomIn();
                flag1 = true;
                if (!theWorldStart)
                {
                    rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y * 0.05f);
                    theWorldStart        = true;
                }
                theWorldEnd = false;
                timeSpeed   = 0.05f;
                rigidbody2D.gravityScale = 0.0025f * gravity;
            }
        }

        if (Input.GetButtonUp("Fire2") && !playerMoving.isPlayerDashing)
        {
            keyHoldTime = 0;
            if (playerMoving.isPlayerDashed == false) //&& (Vector2.Distance(new Vector2(Input.mousePosition.x, Input.mousePosition.y), new Vector2(transform.position.x, transform.position.y)) > 100))
            {
                playerMoving.isPlayerDashed = true;
                Debug.Log("Dash");
                DisableEffects();
                //dash();
            }
        }
        if (playerMoving.isPlayerClimbing == false && playerMoving.isPlayerBlocked == true && (playerMoving.isPlayerJumped == true || GetComponent <Rigidbody2D>().velocity.y < -0.5 * timeSpeed))
        {
            if (Input.GetButton("Fire1") && playerMoving.isPlayerClimbing == false && !playerMoving.isPlayerDashing)
            {
                if (!playerMoving.isPlayerDown)
                {
                    playerCombo.addCombo(5, "攀爬墙壁");
                }
                playerMoving.isPlayerClimbing         = true;
                playerMoving.isPlayerJumped           = true;
                GetComponent <Rigidbody2D>().velocity = new Vector2(0, 8f * timeSpeed);
            }
        }
#endif

        if (flag1 == false)
        {
            cameraFollow.zoomOut();
            if (!theWorldEnd)
            {
                if (!playerMoving.isPlayerDashing)
                {
                    rigidbody2D.velocity = new Vector2(0, rigidbody2D.velocity.y * 20f);
                }
                theWorldEnd = true;
            }
            theWorldStart = false;
            timeSpeed     = 1.0f;
            GetComponent <Rigidbody2D>().gravityScale = gravity;
        }
        if (playerMoving.isPlayerClimbing == true)
        {
            if ((leftClimbingTime -= (timeSpeed)) <= 0 || playerMoving.isPlayerDashing)
            {
                endClimb();
            }
        }
#endif
    }