public void didTapQuadrant(SarcophagusQuadrant quadrant) { Debug.Log("User did tap Quadrant:" + quadrant.type); Debug.Log(quadrant.gameObject); // If nothing is selected, nothing happens, // or we want to move a jar to its own location if (this.selectedJar == null || this.selectedJar.type == quadrant.currentJar) { Debug.Log("No Jar selected"); return; } // If tapping a spot take by another jar, we show error if (quadrant.currentJar != JarType.none) { Debug.Log("Quadrant is already occupied by another jar"); gameObject.GetComponent <PlayMakerFSM>().SendEvent("error"); return; } if (!this.isMovementValid(this.selectedJar.currentQuadrant, quadrant)) { Debug.Log("Jar cannot move to that quadrant"); return; } // Else we slide the jar to the new positon Debug.Log("Sliding Jar:" + this.selectedJar.type + " to quadrant:" + quadrant.type); this.overlay.SetActive(true); Vector3 qPosition = quadrant.gameObject.GetComponent <BoxCollider2D>().bounds.center; qPosition.z = this.selectedJar.gameObject.GetComponent <BoxCollider2D>().bounds.center.z; iTween.MoveTo(this.selectedJar.gameObject, iTween.Hash("position", qPosition, "time", 0.75, "easeType", "linear", "oncomplete", "OnMoveComplete", "oncompletetarget", gameObject)); gameObject.GetComponent <PlayMakerFSM>().SendEvent("play sound"); // Assign jar to the quadrant it moved to quadrant.currentJar = this.selectedJar.type; // Assign to the jar the new quadrant it occupies this.selectedJar.currentQuadrant.currentJar = JarType.none; this.selectedJar.currentQuadrant = quadrant; // Deselect current jar this.selectedJar = null; }
// Public methods public void didTapJar(SarcophagusJar jar) { // Reset if tapping the same jar twice this.selectedJar = (this.selectedJar == jar) ? null : jar; Debug.Log("Jar selected:" + this.selectedJar); }