private void Update() { if (this.continuePlaying && (Input.GetMouseButtonDown(0 /*left button number*/) || Input.touchCount > 0)) { #if !UNITY_EDITOR //to process only first touch bit not continuos pressing if (Input.GetTouch(0).phase != TouchPhase.Began) { return; } #endif //if we press button on screne (e.g. 'google button') we don`t need to put new cube if (EventSystem.current.IsPointerOverGameObject()) { return; } //if we place first cube we need to hide main menu if (this.isFirstCube) { this.isFirstCube = false; foreach (var item in this.mainMenuObjects) { Destroy(item); } } //creating new cube GameObject newCube = Instantiate(this.cubeToCreate, cubeToPlace.position, Quaternion.identity) as GameObject; //make it part of allCubes rigidbody newCube.transform.SetParent(this.allCubes.transform); //update position if last cube currentCube.setVector(newCube.transform.position); //save new occupied(занятое) position this.allCubesPositions.Add(currentCube.getVector()); //draw cube to place in new position this.SpawnPositions(); //to update rigid body to check is tower stable this.allCubes.GetComponent <Rigidbody>().isKinematic = true; this.allCubes.GetComponent <Rigidbody>().isKinematic = false; } //check if main cube is moving if (this.continuePlaying && this.allCubes.GetComponent <Rigidbody>().velocity.magnitude > 0.1f) { //if tower is falling we delete cube to place from scene Destroy(cubeToPlace.gameObject); //stop position spawning this.StopCoroutine(this.showCubePlaceCoroutine); this.continuePlaying = false; } }
// Update is called once per frame void Update() { if (allCubesRB.velocity.magnitude > 0.1f && isLose == false) { Destroy(cubeToPlace.gameObject); StopCoroutine(showCubePlace); isLose = true; RestartButton.SetActive(true); } if ((Input.GetMouseButtonDown(0) || Input.touchCount > 0) && cubeToPlace != null && allCubes != null && isLose == false && !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( cubeToCreate, cubeToPlace.position, Quaternion.identity) as GameObject; newCube.transform.SetParent(allCubes.transform); nowCube.setVector(cubeToPlace.position); allCubesPositions.Add(cubeToPlace.position); allCubesRB.isKinematic = true; allCubesRB.isKinematic = false; SpawnPositions(); MoveCameraChangeBg(); } Vector3 movePos = mainCam.localPosition; movePos.y = cameraMoveY; mainCam.localPosition = Vector3.MoveTowards(mainCam.localPosition, movePos, cameraMoveSpeed * Time.deltaTime); }