├── Screenshot.png ├── ProjectSettings ├── ProjectVersion.txt ├── AudioManager.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── TagManager.asset ├── TimeManager.asset ├── EditorSettings.asset ├── NetworkManager.asset ├── DynamicsManager.asset ├── GraphicsSettings.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── QualitySettings.asset ├── UnityAdsSettings.asset ├── ClusterInputManager.asset ├── EditorBuildSettings.asset └── UnityConnectSettings.asset ├── Assets ├── WSP │ ├── Fonts │ │ ├── CODE_Bold.otf │ │ └── CODE_Bold.otf.meta │ ├── Scenes │ │ ├── WordSearch.unity │ │ └── WordSearch.unity.meta │ ├── Prefabs │ │ ├── background.prefab │ │ ├── letter_box.prefab │ │ ├── background.prefab.meta │ │ └── letter_box.prefab.meta │ ├── Materials │ │ ├── box_material.mat │ │ ├── background_material.mat │ │ ├── box_material.mat.meta │ │ └── background_material.mat.meta │ ├── Textures │ │ ├── background_texture.png │ │ └── background_texture.png.meta │ ├── Words │ │ ├── wordpool.txt.meta │ │ └── wordpool.txt │ ├── Fonts.meta │ ├── Words.meta │ ├── Materials.meta │ ├── Prefabs.meta │ ├── Scenes.meta │ ├── Scripts.meta │ ├── Textures.meta │ └── Scripts │ │ ├── Letters.cs.meta │ │ ├── WordSearch.cs.meta │ │ ├── Letters.cs │ │ └── WordSearch.cs └── WSP.meta ├── .gitignore └── README.rtf /Screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Screenshot.png -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.3.5f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /Assets/WSP/Fonts/CODE_Bold.otf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Fonts/CODE_Bold.otf -------------------------------------------------------------------------------- /Assets/WSP/Scenes/WordSearch.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Scenes/WordSearch.unity -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /Assets/WSP/Prefabs/background.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Prefabs/background.prefab -------------------------------------------------------------------------------- /Assets/WSP/Prefabs/letter_box.prefab: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Prefabs/letter_box.prefab -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /Assets/WSP/Materials/box_material.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Materials/box_material.mat -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /Assets/WSP/Materials/background_material.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Materials/background_material.mat -------------------------------------------------------------------------------- /Assets/WSP/Textures/background_texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/Assets/WSP/Textures/background_texture.png -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/davesshin/Word-Search-Puzzles/HEAD/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /Assets/WSP/Scenes/WordSearch.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 80d5629c787ad984391757deb8970be4 3 | DefaultImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/WSP/Words/wordpool.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fdd1378fd24a4ce4591e0b591d6eb928 3 | TextScriptImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/WSP/Prefabs/background.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b9d78a6ff6a6154ba874b9a60a05a0f 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/WSP/Prefabs/letter_box.prefab.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: df6a556ece0952e469642be48a8f36b8 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/WSP/Materials/box_material.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 32f3bef7d903e1b41a866126d0204612 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/WSP/Materials/background_material.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f6bb6cd8db5a079409e5af71db2ff071 3 | NativeFormatImporter: 4 | userData: 5 | assetBundleName: 6 | assetBundleVariant: 7 | -------------------------------------------------------------------------------- /Assets/WSP.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 56a124a2f8f2bf040bd07c764b52c072 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Fonts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0bd9c3d3760f91a41a0e1d38be19f988 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Words.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9fd6f70e243679344bc3894f64e388e9 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: eb4c5b62c541a3243b835156061e7629 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Prefabs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 988e45dbb268f1d45a6e59fff065308b 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01a7ee3ed834d814cae10e10ba67203d 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8b4b2c947dff948458ba09e56274172a 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddf1c5a21146dd44cb2001dc5f06dc9d 3 | folderAsset: yes 4 | timeCreated: 1472203060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/WSP/Scripts/Letters.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28ca5306a1f77d24ea2dc93f3fad3c72 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/WSP/Scripts/WordSearch.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 37bf3438ed8c444449fdcdc1b095f0b7 3 | MonoImporter: 4 | serializedVersion: 2 5 | defaultReferences: [] 6 | executionOrder: 0 7 | icon: {instanceID: 0} 8 | userData: 9 | assetBundleName: 10 | assetBundleVariant: 11 | -------------------------------------------------------------------------------- /Assets/WSP/Words/wordpool.txt: -------------------------------------------------------------------------------- 1 | assemble;brood;bucolic;comely;conflate;cynosure;demesne;demure;dulcet;elision;elixir;eloquent;epiphany;fetching;furtive;gambol;glamour;gossamer;halcyon;imbue;ingenue;inure;lagoon;languor;leisure;lilt;lissome;lithe;love;moiety;murmur;nemesis;offing;opulent;panacea;panoply;penumbra;plethora;pyrrhic;ravel;redolent;riparian;ripple;summery;talisman;umbrella;untoward;vestige;wafture;xanadu; -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Autogenerated VS/MD solution and project files 9 | ExportedObj/ 10 | *.csproj 11 | *.unityproj 12 | *.sln 13 | *.suo 14 | *.tmp 15 | *.user 16 | *.userprefs 17 | *.pidb 18 | *.booproj 19 | *.svd 20 | 21 | 22 | # Unity3D generated meta files 23 | *.pidb.meta 24 | 25 | # Unity3D Generated File On Crash Reports 26 | sysinfo.txt 27 | 28 | # Builds 29 | *.apk 30 | *.unitypackage 31 | -------------------------------------------------------------------------------- /Assets/WSP/Fonts/CODE_Bold.otf.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f442c5c541227a489bfa763cfb09b5d 3 | timeCreated: 1472203083 4 | licenseType: Pro 5 | TrueTypeFontImporter: 6 | serializedVersion: 3 7 | fontSize: 16 8 | forceTextureCase: -2 9 | characterSpacing: 1 10 | characterPadding: 0 11 | includeFontData: 1 12 | fontNames: [] 13 | fallbackFontReferences: [] 14 | customCharacters: 15 | fontRenderingMode: 0 16 | ascentCalculationMode: 1 17 | userData: 18 | assetBundleName: 19 | assetBundleVariant: 20 | -------------------------------------------------------------------------------- /README.rtf: -------------------------------------------------------------------------------- 1 | by Dave Shin 2 | 3 | 4 | An interactive & customizable word search puzzle generator made with Unity/C#. Great for teaching kids new words and their spellings! 5 | Simply insert any word you want inside the wordpool.txt, and configure the settings via the "Word Search" script attached to the "Main Camera" in Unity Inspector. 6 | 7 | 8 | You may implement, modify, or distribute any or all parts of the scripts/wordpool, all without asking permission. 9 | 10 | 11 | - Identify words by clicking and dragging with the left mouse button. 12 | - Upon correctly identifying each word, the boxes will turn green and an asterisk will appear beside the word. 13 | - The timer will allow you to determine how long the puzzle took you. 14 | -------------------------------------------------------------------------------- /Assets/WSP/Scripts/Letters.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Letters : MonoBehaviour { 5 | 6 | public bool utilized = false; 7 | public bool identified = false; 8 | public TextMesh letter; 9 | public int gridX, gridY; 10 | 11 | void Start() { 12 | GetComponent().materials[0].color = WordSearch.Instance.defaultTint; 13 | } 14 | 15 | void Update() { 16 | if (WordSearch.Instance.ready) { 17 | if (!utilized && WordSearch.Instance.current == gameObject) { 18 | WordSearch.Instance.selected.Add(this.gameObject); 19 | GetComponent().materials[0].color = WordSearch.Instance.mouseoverTint; 20 | WordSearch.Instance.selectedString += letter.text; 21 | utilized = true; 22 | } 23 | } 24 | 25 | if (identified) { 26 | if (GetComponent().materials[0].color != WordSearch.Instance.identifiedTint) { 27 | GetComponent().materials[0].color = WordSearch.Instance.identifiedTint; 28 | } 29 | return; 30 | } 31 | 32 | if (Input.GetMouseButtonUp(0)) { 33 | utilized = false; 34 | if (GetComponent().materials[0].color != WordSearch.Instance.defaultTint) { 35 | GetComponent().materials[0].color = WordSearch.Instance.defaultTint; 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /Assets/WSP/Textures/background_texture.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb2e27d953ccc204abfae1dc6a089e17 3 | timeCreated: 1472203318 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 2 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | linearTexture: 0 12 | correctGamma: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 0 25 | cubemapConvolution: 0 26 | cubemapConvolutionSteps: 7 27 | cubemapConvolutionExponent: 1.5 28 | seamlessCubemap: 0 29 | textureFormat: -1 30 | maxTextureSize: 2048 31 | textureSettings: 32 | filterMode: -1 33 | aniso: 16 34 | mipBias: -1 35 | wrapMode: 1 36 | nPOTScale: 1 37 | lightmap: 0 38 | rGBM: 0 39 | compressionQuality: 50 40 | allowsAlphaSplitting: 0 41 | spriteMode: 0 42 | spriteExtrude: 1 43 | spriteMeshType: 1 44 | alignment: 0 45 | spritePivot: {x: 0.5, y: 0.5} 46 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 47 | spritePixelsToUnits: 100 48 | alphaIsTransparency: 0 49 | textureType: 0 50 | buildTargetSettings: [] 51 | spriteSheet: 52 | sprites: [] 53 | outline: [] 54 | spritePackingTag: 55 | userData: 56 | assetBundleName: 57 | assetBundleVariant: 58 | -------------------------------------------------------------------------------- /Assets/WSP/Scripts/WordSearch.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; using System; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | public class WordSearch : MonoBehaviour { 6 | // you may customize these variables in the Unity Inspector however you want 7 | public bool useWordpool; // 'should we use the wordpool?' 8 | public TextAsset wordpool; // if true, wordpool will be utilized 9 | public string[] words; // overwritten if wordpool = true 10 | public int maxWordCount; // max number of words used 11 | public int maxWordLetters; // max length of word used 12 | public bool allowReverse; // if true, words can be selected in reverse order. 13 | public int gridX, gridY; // grid dimensions 14 | public float sensitivity; // sensitivity of tiles when clicked 15 | public float spacing; // spacing between tiles 16 | public GameObject tile, background, current; 17 | public Color defaultTint, mouseoverTint, identifiedTint; 18 | public bool ready = false, correct = false; 19 | public string selectedString = ""; 20 | public List selected = new List(); 21 | 22 | private List tiles = new List(); 23 | private GameObject temporary, backgroundObject; 24 | private int identified = 0; 25 | private float time; 26 | private string[,] matrix; 27 | private Dictionary word = new Dictionary(); 28 | private Dictionary insertedWords = new Dictionary(); 29 | private string[] letters = new string[26] 30 | {"a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z"}; 31 | private Ray ray; 32 | private RaycastHit hit; 33 | private int mark = 0; 34 | 35 | private static WordSearch instance; 36 | public static WordSearch Instance { 37 | get { 38 | return instance; 39 | } 40 | } 41 | 42 | void Awake() { 43 | instance = this; 44 | } 45 | 46 | void Start() { 47 | List findLength = new List(); 48 | int count = 0; 49 | 50 | if (useWordpool) { 51 | words = wordpool.text.Split(';'); 52 | } else { 53 | maxWordCount = words.Length; 54 | } 55 | 56 | if (maxWordCount <= 0) { 57 | maxWordCount = 1; 58 | } 59 | 60 | Mix(words); 61 | Mathf.Clamp(maxWordLetters, 0, gridY < gridX ? gridX : gridY); 62 | 63 | while (findLength.Count < maxWordCount + 1) { 64 | if (words[count].Length <= maxWordLetters) { 65 | findLength.Add(words[count]); 66 | } 67 | count++; 68 | } 69 | 70 | for (int i = 0; i < maxWordCount; i++) { 71 | if (!word.ContainsKey(findLength[i].ToUpper()) && !word.ContainsKey(findLength[i])) { 72 | word.Add(findLength[i], false); 73 | } 74 | } 75 | 76 | Mathf.Clamp01(sensitivity); 77 | matrix = new string[gridX, gridY]; 78 | InstantiateBG(); 79 | 80 | for (int i = 0; i < gridX; i++) { 81 | for (int j = 0; j < gridY; j++) { 82 | temporary = Instantiate(tile, new Vector3(i * 1 * tile.transform.localScale.x * spacing, 10, j * 1 * tile.transform.localScale.z * spacing), Quaternion.identity) as GameObject; 83 | temporary.name = "tile-" + i.ToString() + "-" + j.ToString(); 84 | temporary.transform.eulerAngles = new Vector3(180, 0, 0); 85 | temporary.transform.parent = backgroundObject.transform; 86 | BoxCollider boxCollider = temporary.GetComponent() as BoxCollider; 87 | boxCollider.size = new Vector3(sensitivity, 1, sensitivity); 88 | temporary.GetComponent().letter.text = ""; 89 | temporary.GetComponent().gridX = i; 90 | temporary.GetComponent().gridY = j; 91 | tiles.Add(tile); 92 | matrix[i, j] = ""; 93 | } 94 | } 95 | CenterBG(); 96 | InsertWords(); 97 | FillRemaining(); 98 | time = Time.time; 99 | } 100 | private void CenterBG() { 101 | backgroundObject.transform.position = Camera.main.ScreenToWorldPoint(new Vector3(Screen.width / 2, (Screen.height / 2) + 50, 200)); 102 | } 103 | 104 | private void InstantiateBG() { 105 | if (gridX % 2 != 0 && gridY % 2 == 0) { 106 | backgroundObject = Instantiate (background, new Vector3 ((tile.transform.localScale.x * spacing) 107 | * (gridX / 2), 1, (tile.transform.localScale.z * spacing) 108 | * (gridY / 2) - (tile.transform.localScale.z * spacing)), Quaternion.identity) as GameObject; 109 | } else if (gridX % 2 == 0 && gridY % 2 != 0) { 110 | backgroundObject = Instantiate (background, new Vector3 ((tile.transform.localScale.x * spacing) * (gridX / 2) 111 | - (tile.transform.localScale.x * spacing), 1, (tile.transform.localScale.z * spacing) * (gridY / 2)), Quaternion.identity) as GameObject; 112 | } else { 113 | backgroundObject = Instantiate(background, new Vector3 ((tile.transform.localScale.x * spacing) * (gridX / 2) - 114 | (tile.transform.localScale.x * spacing), 1, (tile.transform.localScale.z * spacing) * (gridY / 2) - (tile.transform.localScale.z * spacing)), Quaternion.identity) as GameObject; 115 | } 116 | backgroundObject.transform.eulerAngles = new Vector3(180, 0, 0); 117 | backgroundObject.transform.localScale = new Vector3(((tile.transform.localScale.x * spacing) * gridX), 1, ((tile.transform.localScale.x * spacing) * gridY)); 118 | } 119 | 120 | void Update() { 121 | if (Input.GetMouseButton (0)) { 122 | ray = Camera.main.ScreenPointToRay (Input.mousePosition); 123 | if (Physics.Raycast (ray, out hit)) { 124 | current = hit.transform.gameObject; 125 | } 126 | ready = true; 127 | } 128 | if (Input.GetMouseButtonUp (0)) { 129 | ray = Camera.main.ScreenPointToRay (Input.mousePosition); 130 | if (Physics.Raycast (ray, out hit)) { 131 | current = hit.transform.gameObject; 132 | } 133 | Verify(); 134 | } 135 | } 136 | 137 | private void Verify() { 138 | if (!correct) { 139 | foreach (KeyValuePair p in insertedWords) { 140 | if (selectedString.ToLower() == p.Key.Trim().ToLower()) { 141 | foreach (GameObject g in selected) { 142 | g.GetComponent().identified = true; 143 | } 144 | correct = true; 145 | } 146 | if (allowReverse) { 147 | if (Reverse(selectedString.ToLower()) == p.Key.Trim().ToLower()) { 148 | foreach (GameObject g in selected) { 149 | g.GetComponent().identified = true; 150 | } 151 | correct = true; 152 | } 153 | } 154 | } 155 | } 156 | 157 | if (correct) { 158 | insertedWords.Remove(selectedString); 159 | insertedWords.Remove(Reverse(selectedString)); 160 | 161 | if (word.ContainsKey (selectedString)) { 162 | insertedWords.Add (selectedString, true); 163 | } else if (word.ContainsKey (Reverse (selectedString))) { 164 | insertedWords.Add (Reverse (selectedString), true); 165 | } 166 | identified++; 167 | } 168 | ready = false; 169 | selected.Clear(); 170 | selectedString = ""; 171 | correct = false; 172 | } 173 | 174 | private void InsertWords() { 175 | System.Random rn = new System.Random(); 176 | foreach (KeyValuePair p in word) { 177 | string s = p.Key.Trim(); 178 | bool placed = false; 179 | while (placed == false) { 180 | int row = rn.Next(gridX); 181 | int column = rn.Next(gridY); 182 | int directionX = 0; 183 | int directionY = 0; 184 | while (directionX == 0 && directionY == 0) { 185 | directionX = rn.Next(3) - 1; 186 | directionY = rn.Next(3) - 1; 187 | } 188 | placed = InsertWord(s.ToLower(), row, column, directionX, directionY); 189 | mark++; 190 | if (mark > 100) { 191 | break; 192 | } 193 | } 194 | } 195 | } 196 | 197 | private bool InsertWord(string word, int row, int column, int directionX, int directionY) { 198 | if (directionX > 0) { 199 | if (row + word.Length >= gridX) { 200 | return false; 201 | } 202 | } 203 | if (directionX < 0) { 204 | if (row - word.Length < 0) { 205 | return false; 206 | } 207 | } 208 | if (directionY > 0) { 209 | if (column + word.Length >= gridY) { 210 | return false; 211 | } 212 | } 213 | if (directionY < 0) { 214 | if (column - word.Length < 0) { 215 | return false; 216 | } 217 | } 218 | 219 | if (((0 * directionY) + column) == gridY - 1) { 220 | return false; 221 | } 222 | 223 | for (int i = 0; i < word.Length; i++) { 224 | if (!string.IsNullOrEmpty (matrix [(i * directionX) + row, (i * directionY) + column])) { 225 | return false; 226 | } 227 | } 228 | 229 | insertedWords.Add(word, false); 230 | char[] w = word.ToCharArray(); 231 | for (int i = 0; i < w.Length; i++) { 232 | matrix[(i * directionX) + row, (i * directionY) + column] = w[i].ToString(); 233 | GameObject.Find("tile-" + ((i * directionX) + row).ToString() + "-" + ((i * directionY) + column).ToString()).GetComponent().letter.text = w[i].ToString(); 234 | } 235 | return true; 236 | } 237 | 238 | private void FillRemaining() { 239 | for (int i = 0; i < gridX; i++) { 240 | for (int j = 0; j < gridY; j++) { 241 | if (matrix[i, j] == "") { 242 | matrix[i, j] = letters[UnityEngine.Random.Range(0, letters.Length)]; 243 | GameObject.Find("tile-" + i.ToString() + "-" + j.ToString()).GetComponent().letter.text = matrix[i, j]; 244 | } 245 | } 246 | } 247 | } 248 | 249 | private void Mix(string[] words) { 250 | for (int t = 0; t < words.Length; t++) { 251 | string tmp = words[t]; 252 | int r = UnityEngine.Random.Range(t, words.Length); 253 | words[t] = words[r]; 254 | words[r] = tmp; 255 | } 256 | } 257 | 258 | private string TimeElapsed() { 259 | TimeSpan t = TimeSpan.FromSeconds(Mathf.RoundToInt(Time.time - time)); 260 | return String.Format("{0:D2}:{1:D2}", t.Minutes, t.Seconds); 261 | } 262 | 263 | private string Reverse(string word) { 264 | string reversed = ""; 265 | char[] letters = word.ToCharArray(); 266 | for (int i = letters.Length - 1; i >= 0; i--) { 267 | reversed += letters[i]; 268 | } 269 | return reversed; 270 | } 271 | 272 | void OnGUI() { 273 | GUILayout.BeginVertical(); 274 | GUILayout.BeginHorizontal(); 275 | GUILayout.Label(" Timer: "); 276 | GUILayout.Label(TimeElapsed()); 277 | GUILayout.EndHorizontal(); 278 | 279 | foreach (KeyValuePair p in insertedWords) { 280 | GUILayout.BeginHorizontal(); 281 | GUILayout.Label(" " + p.Key); 282 | if (p.Value) { 283 | GUILayout.Label("*"); 284 | } 285 | GUILayout.EndHorizontal(); 286 | } 287 | GUILayout.EndVertical(); 288 | } 289 | } --------------------------------------------------------------------------------