Пример #1
0
 void Awake()
 {
     Toolbox.Log("BlockFloor Awake");
     I = this;
     transform.localScale = Vector3.one;
     startScale           = transform.localScale;
     SpawnFloor();
     GlobalTick.OnInitialized += Init;
 }
Пример #2
0
    IEnumerator OnMouseClicked()
    {
#if UNITY_ANDROID
        int touchCount = Input.touchCount;
        if (touchCount == 0)
        {
            yield return(null);
        }
        else
        {
            for (int j = 0; j < touchCount; j++)
            {
                Touch   touch    = Input.GetTouch(j);
                Vector2 touchPos = touch.position;
                if (touch.phase == TouchPhase.Began)
                {
                    Ray          ray = Camera.main.ScreenPointToRay(touchPos);
                    RaycastHit2D hit = Physics2D.GetRayIntersection(ray, 100f);

                    if (hit.collider && hit.transform.CompareTag("Block"))
                    {
                        Block hitBlock = hit.transform.GetComponent <Block>();
                        StartCoroutine(GettingAchievement());

                        if (hitBlock.IsBreakable)
                        {
                            hitBlock.Hp--;
                            iTween.ShakePosition(hitBlock.gameObject, iTween.Hash("name", "blockShake"
                                                                                  , "x", 0.1f
                                                                                  , "y", 0.1f
                                                                                  , "time", 0.05f
                                                                                  , "oncomplete", "hitBlock.ResetInitPos"
                                                                                  , "oncompletetarget", hitBlock.gameObject));
                            StartCoroutine(PlaySfx(hitSound));

                            if (hitBlock.Hp <= 0)
                            {
                                BlockFloor hitBlockFloor = hitBlock.GetComponentInParent <BlockFloor>();
                                for (int i = 0; i < hitBlockFloor.Block.Length; i++)
                                {
                                    iTween.StopByName(hitBlockFloor.Block[i].gameObject, "blockShake");
                                }
                                hitBlockFloor.ResetLocalPosition();
                                hitBlockFloor.SetBlocksBreakable(false);
                                hitBlock.gameObject.SetActive(false);
                                if (hitBlock.BlockProperty == BlockType.bomb)
                                {
                                    UIMgr.OnGameOver();
                                }
                                blockStack.Push(BlockMove());
                            }
                        }
                    }
                }
            }
        }
#endif
#if UNITY_EDITOR
        if (Input.GetMouseButtonDown(0))
        {
            Ray          ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit2D hit = Physics2D.GetRayIntersection(ray, 100f);

            if (hit.collider && hit.transform.CompareTag("Block"))
            {
                Block hitBlock = hit.transform.GetComponent <Block>();

                if (hitBlock.IsBreakable)
                {
                    hitBlock.Hp--;
                    iTween.ShakePosition(hitBlock.gameObject, iTween.Hash("name", "blockShake"
                                                                          , "x", 0.1f
                                                                          , "y", 0.1f
                                                                          , "time", 0.05f
                                                                          , "oncomplete", "hitBlock.ResetInitPos"
                                                                          , "oncompletetarget", hitBlock.gameObject));
                    StartCoroutine(PlaySfx(hitSound));

                    if (hitBlock.Hp <= 0)
                    {
                        BlockFloor hitBlockFloor = hitBlock.GetComponentInParent <BlockFloor>();
                        for (int i = 0; i < hitBlockFloor.Block.Length; i++)
                        {
                            iTween.StopByName(hitBlockFloor.Block[i].gameObject, "blockShake");
                        }
                        hitBlockFloor.ResetLocalPosition();
                        hitBlockFloor.SetBlocksBreakable(false);
                        hitBlock.gameObject.SetActive(false);
                        if (hitBlock.BlockProperty == BlockType.bomb)
                        {
                            UIMgr.OnGameOver();
                        }
                        blockStack.Push(BlockMove());
                    }
                }
            }
        }
#endif
        yield return(null);
    }
Пример #3
0
 void OnDestroy()
 {
     StopDropping();
     GlobalTick.OnInitialized -= Init;
     I = null;
 }