void Awake() { InitCube(); instance = this; CheckMatch.CheckAllNodes(); }
// Update is called once per frame void Update() { if (rotTimeLeft > 0) { foreach (GameObject go in filteredObjects) { go.transform.position = rot * go.transform.position; } rotTimeLeft--; } else if (rotTimeLeft == 0 && !isChecked) { CheckMatch.CheckAllNodes(); isChecked = true; } else if (CheckMatch.nodesToBeDeleted.Count == 0 && movesLeft > 0) { if (Input.GetKeyDown(KeyCode.Mouse0)) { Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100)) { Vector3 pos = hit.transform.position; hitPos = hit.point; x = Mathf.RoundToInt(pos.x); y = Mathf.RoundToInt(pos.y); z = Mathf.RoundToInt(pos.z); mousePos = Input.mousePosition; } else { x = 0; y = 0; z = 0; } } if (Input.GetKeyUp(KeyCode.Mouse0)) { Vector2 newMousePos = Input.mousePosition; if (Vector2.Distance(newMousePos, mousePos) > 32) { if (x != 0 || y != 0 || z != 0) { Vector3 dragDir = Camera.main.transform.TransformDirection(newMousePos - mousePos); Vector3 hitDir = getGeneralDirection(hitPos); Vector3 axis = Vector3.Cross(dragDir, hitDir); axis = getGeneralDirection(axis); Rotate(x, y, z, axis); filteredObjects.Clear(); float E = 0.1f; foreach (GameObject go in MainController.allObjects) { if (axis.x != 0 && Mathf.Abs(go.transform.position.x - x) < E) { filteredObjects.Add(go); } else if (axis.y != 0 && Mathf.Abs(go.transform.position.y - y) < E) { filteredObjects.Add(go); } else if (axis.z != 0 && Mathf.Abs(go.transform.position.z - z) < E) { filteredObjects.Add(go); } } x = 0; y = 0; z = 0; } } } } if (CheckMatch.nodesToBeDeleted.Count == 0 && movesLeft == 0) { endGame.End(false); } }