//------------------------------------------------------- //////////////////////////// // Locationänderung wenn nach Hinten gedreht wird public void rotationChangerBack() { foreach (GameObject loc in interactCubes) { _cubeLocation = loc.GetComponentInChildren <CubeLocation> (); switch (_cubeLocation.location) { case 0: _cubeLocation.location = 2; break; case 1: _cubeLocation.location = 3; break; case 2: _cubeLocation.location = 1; break; case 3: _cubeLocation.location = 0; break; } } }
//------------------------------------------------------- //} ENDE IENUMERATOR / ANIMATION ////////////////////////////////////////////////////////////////////////////////////////// // ============== // LOCATIONSÄNDERUNGSFUNKTIONEN // ============== //{/////////////////////////////////////////////////////////////////////////////////////// //------------------------------------------------------- //////////////////////////// // Locationänderung wenn nach Links gedreht wird public void rotationChangerLeft() { // Alle Objekte in der Liste werden durchgegangen foreach (GameObject loc in interactCubes) { // Zugriff auf das Script _cubeLocation = loc.GetComponentInChildren <CubeLocation> (); // Switchabfrage um neue Location zu ermitteln switch (_cubeLocation.location) { case 0: _cubeLocation.location = 5; break; case 1: _cubeLocation.location = 4; break; case 4: _cubeLocation.location = 0; break; case 5: _cubeLocation.location = 1; break; } } }
//------------------------------------------------------- //////////////////////////// // Locationänderung wenn nach Rechts gedreht wird public void rotationChangerRight() { foreach (GameObject loc in interactCubes) { _cubeLocation = loc.GetComponentInChildren <CubeLocation> (); switch (_cubeLocation.location) { case 0: _cubeLocation.location = 4; break; case 1: _cubeLocation.location = 5; break; case 4: _cubeLocation.location = 1; break; case 5: _cubeLocation.location = 0; break; } } }
//------------------------------------------------------- //} ENDE GAMEPLAY FUNKTIONEN ////////////////////////////////////////////////////////////////////////////////////////// // ============== // IENUMERATOR / ANIMATION // ============== //{/////////////////////////////////////////////////////////////////////////////////////// //------------------------------------------------------- //////////////////////////// // Die Animation der Rotation des Cubes IEnumerator Animate(Vector3 fromTo) { // Timer wird auf Null gesetzt und die Rotationsrate wird berechnet float timeSinceStarted = 0f; float rate = rotation / duration; // Der Timer wird gestartet while (timeSinceStarted <= rotation) { // Solange der Timer nicht zuende ist, ist der Cube "beschäftigt" und kann erstmal nicht weiter betätigt werden. Die Rotation vom Cube für die Animation werden berechnet und umgesetzt isBusy = true; foreach (GameObject loc in interactCubes) { _cubeLocation = loc.GetComponentInChildren <CubeLocation> (); _cubeLocation.isBusy = true; } timeSinceStarted += Time.deltaTime * rate; transform.RotateAround(center.transform.position, fromTo, Time.deltaTime * rate); yield return(null); } // Die minimale Differenz wird noch hinzugefügt damit es genau 90 Grad gedreht wurde transform.RotateAround(center.transform.position, fromTo, rotation - timeSinceStarted); // Nachdem der Timer zuende ist, ist der Cube wieder interagierbar isBusy = false; foreach (GameObject loc in interactCubes) { _cubeLocation = loc.GetComponentInChildren <CubeLocation> (); _cubeLocation.isBusy = false; } yield return(new WaitForSeconds(0.1f)); }
//------------------------------------------------------- //////////////////////////// // Use this for initialization void Start() { _cubeLocation = GetComponent <CubeLocation>(); startPos = transform.position; // initialiserie Vektoren groundToTop = new Vector3(0, distance, 0); topToGround = new Vector3(0, -distance, 0); frontToBack = new Vector3(0, 0, -distance); backToFront = new Vector3(0, 0, distance); leftToRight = new Vector3(distance, 0, 0); rightToLeft = new Vector3(-distance, 0, 0); }