Example #1
0
    private void Update()
    {
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && cubeToPlace != null)
        {
            GameObject newCube = Instantiate(
                cubeToCreate,
                cubeToPlace.position,
                Quaternion.identity) as GameObject;

            newCube.transform.SetParent(allCubes.transform);
            nowCube.setVector(cubeToPlace.position);
            allCubesPositions.Add(nowCube.GetVector());
            score++;

            allCubesRB.isKinematic = true;
            allCubesRB.isKinematic = false;
            SpawnPositions();
        }
        if (!isLose && allCubesRB.velocity.magnitude > 0.1f)
        {
            Destroy(cubeToPlace.gameObject);
            isLose = true;
            StopCoroutine(showCubePlace);
        }
    }
Example #2
0
    private void Update()
    {
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && cubeToPlace != null)
        {
            #if !UNITY_EDITOR
            if (Input.GetTouch(0).phase == TouchPhase.Began)
            {
                return;
            }
            #endif
            GameObject newCube = Instantiate(cubeToCreate, cubeToPlace.position, Quaternion.identity) as GameObject;
            newCube.transform.SetParent(allCubes.transform);
            nowCube.setVector(cubeToPlace.position);
            allCubesPositions.Add(nowCube.getVector());
            allCubesRb.isKinematic = true;
            allCubesRb.isKinematic = false;
            SpawnPositions();
        }

        if (!IsLose && allCubesRb.velocity.magnitude > 0.1f)
        {
            Destroy(cubeToPlace.gameObject);
            IsLose = true;
            StopCoroutine(showCubePlace);
        }
    }
Example #3
0
    private void Update()
    {
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && CubeToPlace != null && AllCubes != null && !EventSystem.current.IsPointerOverGameObject())
        {
#if !UNITY_EDITOR
            if (Input.GetTouch(0).phase != TouchPhase.Began)
            {
                return;
            }
#endif

            if (!firstCube)
            {
                firstCube = true;
                foreach (GameObject obj in canvasStartPage)
                {
                    Destroy(obj);
                }
            }

            GameObject newCube = Instantiate(CubesToCreate[UnityEngine.Random.Range(0, CubesToCreate.Length)], CubeToPlace.position, Quaternion.identity) as GameObject;

            newCube.transform.SetParent(AllCubes.transform);
            nowCube.setVector(CubeToPlace.position);
            AllCubePositions.Add(nowCube.GetVector());

            GameObject newVfx = Instantiate(vfx, newCube.transform.position, Quaternion.identity) as GameObject;

            Destroy(newVfx, 1.5f);

            if (PlayerPrefs.GetString("music") != "No")
            {
                GetComponent <AudioSource>().Play();
            }

            AllCubesRb.isKinematic = true;
            AllCubesRb.isKinematic = false;

            SpawnPositions();
            MoveCameraChangeBg();
        }

        if (!IsLose && AllCubesRb.velocity.magnitude > 0.1f)
        {
            Destroy(CubeToPlace.gameObject);
            IsLose = true;
            StopCoroutine(shpowCubePlace);
        }

        mainCam.localPosition = Vector3.MoveTowards(mainCam.localPosition,
                                                    new Vector3(mainCam.localPosition.x, camMoveToYPosition, mainCam.localPosition.z),
                                                    camMoveSpeed * Time.deltaTime);

        if (Camera.main.backgroundColor != toCameraColor)
        {
            Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, toCameraColor, Time.deltaTime / 1.5f);
        }
    }
Example #4
0
    private void Update()
    {
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && (cubeToPlace != null) && (allCubes != null) && (!EventSystem.current.IsPointerOverGameObject(Input.GetTouch(0).fingerId)))
        {
#if !UNITY_ANDROID
            if (Input.GetTouch(0).phase != TouchPhase.Began)
            {
                return;
            }
#endif


            if (!firstCube)
            {
                firstCube = true;
                foreach (GameObject obj in canvasStartPage)
                {
                    Destroy(obj);
                }
            }



            GameObject createCube = null;
            if (possibleCubes.Count == 1)
            {
                createCube = possibleCubes[0];
            }
            else
            {
                createCube = possibleCubes[UnityEngine.Random.Range(0, possibleCubes.Count)];
            }
            GameObject newCube = Instantiate(createCube, cubeToPlace.position, Quaternion.identity) as GameObject;
            newCube.transform.SetParent(allCubes.transform);
            nowCube.setVector(cubeToPlace.position);
            allCubesPos.Add(nowCube.getVector());

            GameObject newVfx = Instantiate(vfx, newCube.transform.position, Quaternion.identity);
            Destroy(newVfx, 1.5f);
            allCubesRb.isKinematic = true;
            allCubesRb.isKinematic = false;
            SpawnPos();
            MoveCameraBg();
        }
        if (!isLose && allCubesRb.velocity.magnitude > 0.1f)
        {
            Destroy(cubeToPlace.gameObject);
            isLose = true;
            StopCoroutine(showCubePlace);
        }
        mainCam.localPosition = Vector3.MoveTowards(mainCam.localPosition, new Vector3(mainCam.localPosition.x, camMoveYPos, mainCam.localPosition.z), camMoveSpeed * Time.deltaTime);

        if (Camera.main.backgroundColor != toCameraColor)
        {
            Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, toCameraColor, Time.deltaTime / 1.5f);
        }
    }
Example #5
0
    private void Update()
    {
        if (Input.GetMouseButtonDown(0) || Input.touchCount > 0)
        {
#if !UNITY_EDITOR
            if (Input.GETTOUCH(0).phase != TouchPhase.Began)
            {
                return;
            }
#endif
            GameObject newCube = Instantiate(cubeToCreate, cubeToPlace.position, Quaternion.identity) as GameObject;
            newCube.transform.SetParent(allCubes.transform);
            nowCube.setVector(cubeToPlace.position);
            allCubesPositions.Add(nowCube.getVector());
            allCubesRb.isKinematic = true;
            allCubesRb.isKinematic = false;
            SpawnPosition();
        }
    }
Example #6
0
    private void Update()
    {
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && cubeToPlace != null && allCubes != null && !EventSystem.current.IsPointerOverGameObject())
        {
#if !UNITY_EDITOR
            if (Input.GetTouch(0).phase != TouchPhase.Began)
            {
                return;
            }
#endif
            if (!firstCube) //нажатие на экран и все элементы скрыть
            {
                firstCube = true;
                foreach (GameObject obj in canvasStartPage)
                {
                    Destroy(obj); //удаление при запуске игры
                }
            }

            GameObject createCube = null;
            if (posibleCubesToCreate.Count == 1)
            {
                createCube = posibleCubesToCreate[0];
            }
            else
            {
                createCube = posibleCubesToCreate[UnityEngine.Random.Range(0, posibleCubesToCreate.Count)];
            }

            GameObject newCube = Instantiate(
                createCube,
                cubeToPlace.position,
                Quaternion.identity) as GameObject;

            newCube.transform.SetParent(allCubes.transform);
            nowCube.setVector(cubeToPlace.position);
            allCubesPositions.Add(nowCube.getVector());

            if (PlayerPrefs.GetString("music") != "No")
            {
                GetComponent <AudioSource>().Play();
            }

            GameObject newvfx = Instantiate(vfx, cubeToPlace.position, Quaternion.identity) as GameObject;
            Destroy(newvfx, 1.5f);

            allCubesRb.isKinematic = true;
            allCubesRb.isKinematic = false;

            SpawnPosition();
            MoveCameraChangeBg(); // проверяем какоц у нас сейчас максимальный кубик и передвигать камеру
        }

        if (!IsLose && allCubesRb.velocity.magnitude > 0.1f) //является ли башня стабильна если он начинается крениться
        {
            Destroy(cubeToPlace.gameObject);
            IsLose = true;
            StopCoroutine(showCubePlace); //
        }
        mainCam.localPosition = Vector3.MoveTowards(mainCam.localPosition,
                                                    new Vector3(mainCam.localPosition.x, camMoveToYPosition, mainCam.localPosition.z),
                                                    camMoveSpeed * Time.deltaTime);

        if (Camera.main.backgroundColor != toCameraColor)
        {
            Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, toCameraColor, Time.deltaTime / 1.5f);
        }
    }
Example #7
0
    private void Update()
    {
        //Если нажата левая кнопка мыши, или пальцев на экране больше чем 1, и есть хотя бы один кубик на экране
        if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && cubeToPlace != null && allCubes != null && !EventSystem.current.IsPointerOverGameObject())
        {
            //Если запускаем не в юнити
#if !UNITY_EDITOR
            if (Input.GetTouch(0).phase != TouchPhase.Began)
            {
                return;
            }
#endif
            // Пока не произойдет нажатия не на кнопку, игра не начнется. Если нажали не на кнопку, уничтожаем кнопки в списке который передаем в юнити
            if (!firstTouch)
            {
                firstTouch = true;
                foreach (GameObject obj in CanvasStartPage)
                {
                    Destroy(obj);
                }
            }

            GameObject createCube = null;
            if (possibleCubesToCreate.Count == 1)
            {
                createCube = possibleCubesToCreate[0];
            }
            else
            {
                createCube = possibleCubesToCreate[UnityEngine.Random.Range(0, possibleCubesToCreate.Count)];
            }

            // Создаем объект на основе первоначального кубика, на изначальном месте, которые мы задаем
            GameObject newCube = Instantiate(createCube, cubeToPlace.position, Quaternion.identity) as GameObject;

            // Пихаем этот кубик в AllCubes
            newCube.transform.SetParent(allCubes.transform);
            // Получаем вектор, где этот кубик поставился
            nowCube.setVector(cubeToPlace.position);
            // Пихаем в занятые позиции этот вектор
            allCubesPositions.Add(nowCube.getVector());

            //Создаем эффект в том месте где ставим куб
            Instantiate(cubeEffect, newCube.transform.position, Quaternion.identity);

            //Обновляем физику кубиков
            UpdatePhysic.isKinematic = true;
            UpdatePhysic.isKinematic = false;

            // Показываем возможные позиции для куба, меняем цвет бекграунда
            SpawnPositions();
            MoveCameraChangeBg();
        }

        // Если еще не проиграли, и вся башня из кубиков пошатнулась
        if (!IsLose && UpdatePhysic.velocity.magnitude > 0.1f)
        {
            //Уничтожаем кубик-позицию(синий), и говорим что произошел луз. Останаливаем курутину.
            Destroy(cubeToPlace.gameObject);
            IsLose = true;
            StopCoroutine(showCubePlace);
        }

        //Поднимаем камеру вверх или вниз, в зависимости от того куда поставился куб.
        mainCam.localPosition = Vector3.MoveTowards(mainCam.localPosition, new Vector3(mainCam.localPosition.x, deltaY, mainCam.localPosition.z), CameraSpeed * Time.deltaTime);
        // Если надо поменять цвет бекграунда
        if (Camera.main.backgroundColor != toCameraColor)
        {
            // Меняем цвет плавно
            Camera.main.backgroundColor = Color.Lerp(Camera.main.backgroundColor, toCameraColor, Time.deltaTime / 1.5f);
        }
    }