Exemplo n.º 1
0
    public void AIJump()
    {
        if (Time.time - jumpLastTime < jumpInterval)
        {
            return;
        }
        bool doJump = true;

        if (doJump)
        {
            jumpLastTime = Time.time;
            controller2D.DoJump();
        }
    }
    public IEnumerator AIJump()
    {
        if (AIType != alwaysJumpAIType)
        {
            if (Time.time - jumpLastTime < jumpInterval)
            {
                yield break;
            }
        }
        bool doJump = false;

        if (Mathf.Abs(footballPos.x - playerPos.x) < 3f ||
            Mathf.Abs(newFootballPos.x - playerPos.x) < 3f ||
            Mathf.Abs(playerPos.x - oppoPlayerTrans.position.x) < 2f)
        {
            if (newFootballPos.y > 3f && newFootballPos.y < 5f)      // if can push ball when jump.
            {
                doJump = true;
            }
        }
        if (playerPos.x < -5f && footballPos.x > playerPos.x - 3f && footballPos.x < playerPos.x)
        // if near goal, AI should push ball lower.
        {
            if (newFootballPos.y < 1.5f)
            {
                doJump = true;
            }
            else
            {
                doJump = false;
            }
        }

        if (doJump || AIType == alwaysJumpAIType)
        {
            jumpLastTime = Time.time;
            yield return(new WaitForSeconds(delay));

            controller2D.DoJump();
        }
    }
Exemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (GameController.Instance.pannelManager.CurrentPanel != null &&
            GameController.Instance.pannelManager.CurrentPanel.name == "BtnControllPanel")
        {
                        #if (UNITY_EDITOR)
            if (Input.GetMouseButton(0) || Input.GetMouseButtonDown(0) || Input.GetMouseButtonUp(0))
            {
                if (Input.mousePosition.x < Screen.width / 2f)
                {
                    ray = guiCamera.ScreenPointToRay(Input.mousePosition);
                    if (Physics.Raycast(ray, out hit, 2000) && hit.collider.tag == "_ControllPanel")
                    {
                        fingerPos = hit.point;
                        if (Input.GetMouseButtonDown(0))
                        {
                            sliderPos = fingerPos;
                            if (sliderPos.x < minRayX)
                            {
                                sliderPos = new Vector3(minRayX, sliderPos.y, 0f);
                            }
                            else if (sliderPos.x > maxRayX)
                            {
                                sliderPos = new Vector3(maxRayX, sliderPos.y, 0f);
                            }
                            else
                            {
                                sliderPos = new Vector3(sliderPos.x, sliderPos.y, 0f);
                            }
                            Slider.transform.position = sliderPos;
                            Slider.SetActiveRecursively(true);
                            SliderButton.transform.position = new Vector3(fingerPos.x, fingerPos.y, 0f);
                        }
                        if (Input.GetMouseButtonUp(0))
                        {
                            Slider.SetActiveRecursively(false);
                        }
                        else
                        {
                            float delta = fingerPos.x - sliderPos.x;
                            delta = Mathf.Clamp(delta, -sliderwidth / 2f, sliderwidth / 2f);
                            SliderButton.transform.position = sliderPos + new Vector3(delta, 0f, 0f);
                            float moveAmount = delta / (sliderwidth / 2f);
                            moveAmount = Mathf.Clamp(moveAmount, -1f, 1f);
                            controller2D.DoMoveAmount(moveAmount);
                        }
                    }
                    else
                    {
                        Slider.SetActiveRecursively(false);
                    }
                }
                else
                {
                    Slider.SetActiveRecursively(false);
                }
            }
                        #endif

            foreach (Touch touch in Input.touches)
            {
                if (touch.position.x < Screen.width / 2f || touch.fingerId == curFingerID)
                {
                    ray = guiCamera.ScreenPointToRay(touch.position);
                    if (Physics.Raycast(ray, out hit, 2000) && hit.collider.tag == "_ControllPanel")
                    {
                        fingerPos = hit.point;
                        switch (touch.phase)
                        {
                        case TouchPhase.Began:
                            if (curFingerID == -1)
                            {
                                curFingerID = touch.fingerId;
                                sliderPos   = fingerPos;
                                if (sliderPos.x < minRayX)
                                {
                                    sliderPos = new Vector3(minRayX, sliderPos.y, 0f);
                                }
                                else if (sliderPos.x > maxRayX)
                                {
                                    sliderPos = new Vector3(maxRayX, sliderPos.y, 0f);
                                }
                                else
                                {
                                    sliderPos = new Vector3(sliderPos.x, sliderPos.y, 0f);
                                }
                                Slider.transform.position = sliderPos;
                                Slider.SetActiveRecursively(true);
                                SliderButton.transform.position = new Vector3(fingerPos.x, fingerPos.y, 0f);
                            }
                            goto default;

                        case TouchPhase.Ended:
                            if (touch.fingerId == curFingerID)
                            {
                                curFingerID = -1;
                                Slider.SetActiveRecursively(false);
                            }
                            break;

                        default:
                            if (touch.fingerId == curFingerID)
                            {
                                float delta = fingerPos.x - sliderPos.x;
                                delta = Mathf.Clamp(delta, -sliderwidth / 2f, sliderwidth / 2f);
                                SliderButton.transform.position = sliderPos + new Vector3(delta, 0f, 0f);
                                float moveAmount = delta / (sliderwidth / 2f);
                                moveAmount = Mathf.Clamp(moveAmount, -1f, 1f);
                                controller2D.DoMoveAmount(moveAmount);
                            }
                            break;
                        }
                    }
                    else
                    {
                        if (touch.fingerId == curFingerID)
                        {
                            curFingerID = -1;
                            Slider.SetActiveRecursively(false);
                        }
                    }
                }
            }
        }


        /// For PC Detect
        if (Input.GetButton("Jump"))
        {
            controller2D.DoJump();
        }
        if (Input.GetKey("space"))
        {
            controller2D.DoShoot();
        }
        if (Input.GetAxis("Horizontal") != 0)
        {
            controller2D.DoMoveAmount(Input.GetAxis("Horizontal"));
        }
        if (Input.GetKey("return"))
        {
            GameController.Instance.UseSkillMe();
        }
        /// For iOS Detect
        /// Cause by the UIButton
    }