// Eliminate a pair and check if there are more stones left private void TwoSameStones(StonePrefab st, StonePrefab st2) { MusicController.Instance.twoSameSound.PlayDelayed(1.10f); StoneCouplesLeft--; if (StoneCouplesLeft == 0) { LevelComplete(); } }
/* Raycast from center eye camera and check if it's * a StonePrefab then pass it to the OnStonePressed() */ private void RaycastStone() { RaycastHit hit; if (Physics.Raycast(cameraTransform.position, cameraTransform.forward, out hit)) { if (hit.collider.gameObject.CompareTag("StonePrefab")) { StonePrefab st = hit.collider.GetComponent <StonePrefab>(); OnStonePressed(st); } } }
public void OnStonePressed(StonePrefab st) { // Check if the stone is available (not spinning and active) if (st.Stone.IsStoneActive == true && IsSpinning == false) { // If so update the turns count, spin the stone and make it inactive turns++; UpdateMovesText(); RotateStone(st); st.Stone.IsStoneActive = false; //Check if it's the first clicked stone if so asign it to 'FirstStone' if (FirstStone == null) { FirstStone = st; IsSpinning = false; } //If it's the second one, compere both ID's else { /* If the absolute value of both ID's is the same * call TwoSameStones method and set stones to null (You've guessed one pair) */ if (Mathf.Abs(st.Stone.StoneID) == Mathf.Abs(FirstStone.Stone.StoneID)) { IsSpinning = false; TwoSameStones(st, FirstStone); st = null; FirstStone = null; } /*If not rotate them back, and set them to null*/ else { RotateStone(FirstStone, st); FirstStone.Stone.IsStoneActive = true; st.Stone.IsStoneActive = true; FirstStone = null; st = null; } } } }
//Overload for two stones private void RotateStone(StonePrefab st, StonePrefab st2) { MusicController.Instance.spinStoneSound.Play(); StartCoroutine(RotateObjectsAfterSomeTime(st.transform, st2.transform, 180f, 0f, 1f)); }
//Rotate a Stone on 180 degree private void RotateStone(StonePrefab st) { MusicController.Instance.spinStoneSound.Play(); StartCoroutine(RotateObject(st.transform, 0f, 180f, 1f)); }