コード例 #1
0
    public void Update_GM()
    {
        if (isDie)
        {
            return;
        }

        //마우스 첫번째 좌표
        if (Input.GetMouseButtonDown(0))
        {
            firstPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
        }

        // 모든 움직임이 끝나면 쏠 수 있음
        shotable = true;
        for (int i = 0; i < BallGroup.childCount; i++)
        {
            if (BallGroup.GetChild(i).GetComponent <OneCommand>().isMoving)
            {
                shotable = false;
            }
        }
        if (isBlockMoving)
        {
            shotable = false;
        }

        if (!shotable)
        {
            return;
        }

        // 모든 공이 바닥에 부딪히면 한 번 실행
        if (shotTrigger && shotable)
        {
            shotTrigger = false;
            BlockGenerator();
            timeDelay = 0;

            StartCoroutine(BallCountTextShow(GreenBallGroup.childCount));
            for (int i = 0; i < GreenBallGroup.childCount; i++)
            {
                StartCoroutine(GreenBallMove(GreenBallGroup.GetChild(i)));
            }
        }

        timeDelay += Time.deltaTime;
        if (timeDelay < 0.1f)
        {
            return;                   // 0.1초 딜레이로 너무 빠르게 손떼면 라인이 남는 버그 제거
        }
        bool isMouse = Input.GetMouseButton(0);

        if (isMouse)
        {
            // 차이값
            secondPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
            if ((secondPos - firstPos).magnitude < 1)
            {
                return;
            }
            gap = (secondPos - firstPos).normalized;
            gap = new Vector3(gap.y >= 0 ? gap.x : gap.x >= 0 ? 1 : -1, Mathf.Clamp(gap.y, 0.2f, 1), 0);

            //화살표, 공 미리보기
            Arrow.transform.position       = veryFirstPos;
            Arrow.transform.rotation       = Quaternion.Euler(0, 0, Mathf.Atan2(gap.y, gap.x) * Mathf.Rad2Deg);
            BallPreview.transform.position =
                Physics2D.CircleCast(new Vector2(Mathf.Clamp(veryFirstPos.x, -54, 54), groundY), 1.7f, gap, 10000, 1 << LayerMask.NameToLayer("Wall") | 1 << LayerMask.NameToLayer("Block")).centroid;

            RaycastHit2D hit = Physics2D.Raycast(veryFirstPos, gap, 10000, 1 << LayerMask.NameToLayer("Wall"));
            // 라인
            MouseLR.SetPosition(0, firstPos);
            MouseLR.SetPosition(1, secondPos);
            BallLR.SetPosition(0, veryFirstPos);
            BallLR.SetPosition(1, (Vector3)hit.point - gap * 1.5f);
        }
        BallPreview.SetActive(isMouse);
        Arrow.SetActive(isMouse);

        if (Input.GetMouseButtonUp(0))
        {
            if ((secondPos - firstPos).magnitude < 1)
            {
                return;
            }
            // 라인 초기화
            MouseLR.SetPosition(0, Vector3.zero);
            MouseLR.SetPosition(1, Vector3.zero);
            BallLR.SetPosition(0, Vector3.zero);
            BallLR.SetPosition(1, Vector3.zero);

            timerStart   = true;
            veryFirstPos = Vector3.zero;
            firstPos     = Vector3.zero;
        }
    }
コード例 #2
0
ファイル: GameManager.cs プロジェクト: Hoguma/SlaytheBrick
    // Update is called once per frame
    void Update()
    {
        // 죽으면 실행 안함
        if (isDie)
        {
            return;
        }

        //클릭하면 클릭한 지점을 저장
        if (Input.touchCount > 0 || Input.GetMouseButtonDown(0) && firstPos == Vector3.zero)
        {
            if (!EventSystem.current.IsPointerOverGameObject() || !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                firstPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
            }
        }


        shotable = true;
        //볼이 움직이고 있으면 쏠 수 없음
        for (int i = 0; i < BallGroup.childCount; i++)
        {
            if (BallGroup.GetChild(i).GetComponent <Ball>().isMoving)
            {
                shotable = false;
            }
        }

        //블럭이 내려올때 쏠 수 없음
        if (isBlockMoving)
        {
            shotable = false;
        }

        //쏠 수 없으면 실행안함
        if (!shotable)
        {
            return;
        }

        //
        if (shotTrigger && shotable)
        {
            shotTrigger = false;
            if (!ice)
            {
                BlockGenerator();
            }
            else
            {
                ice = false;
            }
            timeDelay = 0;


            for (int i = 0; i < GreenBallGroup.childCount; i++)
            {
                StartCoroutine(GreenBallMove(GreenBallGroup.GetChild(i)));
            }
            StartCoroutine(BallCountTextShow(GreenBallGroup.childCount));

            if (coinObtain == 3)
            {
                COcount++;
                if (COcount >= 5)
                {
                    COcount    = 0;
                    coinObtain = 1;
                }
            }

            if (shadow)
            {
                shadow = false;
                for (int i = 0; i < BallGroup.childCount / 2; i++)
                {
                    Destroy(BallGroup.GetChild(i).gameObject);
                }
                BallCountText.text = "x" + BallGroup.childCount.ToString();
            }
            if (gold)
            {
                gold = false;
            }
        }

        //
        timeDelay += Time.deltaTime;
        if (timeDelay < 0.1f)
        {
            return;
        }

        //입력
        bool isMouse = Input.GetMouseButton(0);

        if (Input.touchCount > 0 || isMouse)
        {
            if (!EventSystem.current.IsPointerOverGameObject() || !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                if (isGBallMove)
                {
                    isGBallMove = false;
                    for (int i = 0; i < GreenBallGroup.childCount; i++)
                    {
                        StartCoroutine(GreenBallMove(GreenBallGroup.GetChild(i)));
                    }
                    StartCoroutine(BallCountTextShow(GreenBallGroup.childCount));
                }

                secondPos = Camera.main.ScreenToWorldPoint(Input.mousePosition) + new Vector3(0, 0, 10);
                if ((secondPos - firstPos).magnitude < 1)
                {
                    return;
                }

                gap = (secondPos - firstPos).normalized;
                gap = new Vector3(gap.y >= 0 ? gap.x : gap.x >= 0 ? 1 : -1, Mathf.Clamp(gap.y, 0.2f, 1), 0);

                Arrow.transform.position       = veryFirstPos;
                Arrow.transform.rotation       = Quaternion.Euler(0, 0, Mathf.Atan2(gap.y, gap.x) * Mathf.Rad2Deg);
                BallPreview.transform.position =
                    Physics2D.CircleCast(new Vector2(Mathf.Clamp(veryFirstPos.x, -54, 54), groundY), 1.7f, gap, 10000, 1 << LayerMask.NameToLayer("Wall") | 1 << LayerMask.NameToLayer("Block")).centroid;

                RaycastHit2D hit1 = Physics2D.Raycast(veryFirstPos, gap, 10000, 1 << LayerMask.NameToLayer("Wall"));

                MouseLR.SetPosition(0, firstPos);
                MouseLR.SetPosition(1, secondPos);
                BallLR.SetPosition(0, veryFirstPos);
                BallLR.SetPosition(1, (Vector3)hit1.point - gap * 1.5f);
            }
        }
        else
        {
            isGBallMove = true;
        }

        //터치중 일때 표시선 온
        BallPreview.SetActive(isMouse && !EventSystem.current.IsPointerOverGameObject() || Input.touchCount > 0 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId));
        Arrow.SetActive(isMouse && !EventSystem.current.IsPointerOverGameObject() || Input.touchCount > 0 && !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId));

        //터치를 땟을때 초기화
        if (Input.touchCount > 0 || Input.GetMouseButtonUp(0))
        {
            Debug.Log("hi");

            if (!EventSystem.current.IsPointerOverGameObject() || !EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId))
            {
                Debug.Log("bye");
                if ((secondPos - firstPos).magnitude < 1)
                {
                    return;
                }

                MouseLR.SetPosition(0, Vector3.zero);
                MouseLR.SetPosition(1, Vector3.zero);
                BallLR.SetPosition(0, Vector3.zero);
                BallLR.SetPosition(1, Vector3.zero);

                timerStart   = true;
                veryFirstPos = Vector3.zero;
                firstPos     = Vector3.zero;
            }
        }
    }