void Update() { if (hasWon) { if (Input.GetMouseButtonDown(0)) { displayController.EndGameUINext(); } } #if UNITY_EDITOR if (Input.GetMouseButtonUp(0)) //Avoid accidental clicking { PinZiPP selectedSide = GetSelectedSide(Input.mousePosition); if (selectedSide != null) { SelectSide(selectedSide); } } #endif #if UNITY_STANDALONE if (Input.GetMouseButtonUp(0)) //Avoid accidental clicking { PinZiPP selectedSide = GetSelectedSide(Input.mousePosition); if (selectedSide != null) { SelectSide(selectedSide); } } #endif }
public void ClickedHere(Vector3 touchPosition) //Receive touchInput from RotateCube { PinZiPP selectedSide = GetSelectedSide(Input.mousePosition); if (selectedSide != null) { SelectSide(selectedSide); } }
private void SelectSide(PinZiPP side) { if (!isPlaying) { return; } if (curSelections [0] == null) { displayController.SelectSide(side); curSelections [0] = side.sidename; Debug.Log("curSelection[0] is " + side.sidename); } else { if (curSelections [0] == side.sidename) { curSelections = new string[2]; Debug.Log("curSelection[0] is " + "de-selected."); displayController.SelectSide(side); } else { displayController.SelectSide(side); curSelections [1] = side.sidename; Debug.Log("curSelection[1] is " + side.sidename); if (HasPlayerWon()) { if (hasWon) { Debug.Log("has already won this round"); return; } hasWon = true; isPlaying = false; audioSource.PlayOneShot(winSound); displayController.DisplayWin(); dataController.WinThisRound(); } else { Debug.Log("Wrong Selection!" + " Correct answer is" + curWord.correctSides[0] + ", " + curWord.correctSides[1]); displayController.UnselectAllSides(); curSelections = new string[2]; audioSource.PlayOneShot(loseSound); isPlaying = false; displayController.DisplayLose(); } } } }
/** * Gets the side being selected based on position * Returns null if no side is being selected */ private PinZiPP GetSelectedSide(Vector3 position) { Ray ray = Camera.main.ScreenPointToRay(position); RaycastHit hitInfo; PinZiPP side = null; if (Physics.Raycast(ray, out hitInfo, Mathf.Infinity, 1 << LayerMask.NameToLayer("PinZiSide"))) { if (hitInfo.collider.gameObject.GetComponent <PinZiPP> () != null) { side = hitInfo.collider.gameObject.GetComponent <PinZiPP> (); } } return(side); }
public void SelectSide(PinZiPP side) { side.SetSelected(); if (selectedSides [0] == null) // record what has been selected for UnselectAllSides { selectedSides [0] = side; } else { if (selectedSides [0] == side) { UnselectAllSides(); } else { selectedSides [1] = side; } } }
IEnumerator LoadPinZiResources() { string[] sides = word.sides; texture2DSides = new Texture2D[sides.Length]; texture2DSidesSelected = new Texture2D[sides.Length]; //Debug.Log ("Start Loading"); for (int i = 0; i < sides.Length; i++) { string strTexturePath = "PinZiPianPang/" + sides [i].ToString(); //Debug.Log ("Loading " + (i+1) + " " +strTexturePath); texture2DSides[i] = Resources.Load(strTexturePath) as Texture2D; texture2DSidesSelected[i] = Resources.Load(strTexturePath + "r") as Texture2D; //Debug.Log ("Loaded " + texture2DSides [i].name); //Debug.Log ("Loading... " + (i+1) + "/" + sides.Length); yield return(new WaitForFixedUpdate()); } string strCorrectTexturePath = "PinZiPianPang/" + word.name.ToString(); texture2DAns = Resources.Load(strCorrectTexturePath) as Texture2D; //Debug.Log ("Loaded " + texture2DAns.name); //Debug.Log ("Start assigning"); for (int i = 0; i < sides.Length; i++) { priPrefabPianPangs[i] = GameObjectUtility.customInstantiate(prefabPianPangs [i], goPlaceHolders[i].transform.position, goPlaceHolders[i].transform.rotation); priPrefabPianPangs [i].transform.parent = goTetra.transform; //Debug.Log ("Getting pinZiScript"); PinZiPP pinZiScript = priPrefabPianPangs[i].GetComponent <PinZiPP> (); //Debug.Log ("Initializing"); pinZiScript.Initialize(); //Debug.Log ("Setting texture"); pinZiScript.SetDisplay(texture2DSides [i], texture2DSidesSelected[i]); pinZiScript.sidename = texture2DSides [i].name; //Debug.Log ("-----------Assigned: " + (i + 1) + "/" + sides.Length + "------------"); yield return(new WaitForFixedUpdate()); } }