Created
April 30, 2023 03:42
-
-
Save pemby/f225e8870e3a4ba08f90827798d87d25 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections; | |
using System.Collections.Generic; | |
using UnityEngine; | |
public class Main : MonoBehaviour | |
{ | |
public int[,] aConfig = new int[,] | |
{ | |
{ 0, 0, 1, 1, 1, 0, 0 }, | |
{ 0, 1, 0, 0, 0, 1, 0 }, | |
{ 1, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 1, 1, 1, 1, 1, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0, 1 } | |
}; | |
int[,] bConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0, 1, 0, 0 }, | |
{ 1, 1, 1, 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0, 1, 0, 0 }, | |
{ 1, 1, 1, 1, 0, 0, 0 }, | |
}; | |
int[,] cConfig = new int[,] | |
{ | |
{ 0, 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0 }, | |
{ 1, 0, 0, 0, 0, 0 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 1, 1, 1, 1, 0 }, | |
}; | |
int[,] dConfig = new int[,] | |
{ | |
{ 1, 1, 1, 0, 0, 0 }, | |
{ 1, 0, 0, 1, 0, 0 }, | |
{ 1, 0, 0, 1, 0, 0 }, | |
{ 1, 0, 0, 1, 0, 0 }, | |
{ 1, 1, 1, 0, 0, 0 }, | |
}; | |
int[,] eConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0 }, | |
{ 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0 }, | |
{ 1, 1, 1, 1, 0 }, | |
}; | |
int[,] fConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0 }, | |
{ 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0 }, | |
{ 1, 0, 0, 0, 0 }, | |
}; | |
int[,] gConfig = new int[,] | |
{ | |
{ 0, 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0 }, | |
{ 1, 0, 0, 1, 1, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 1, 1, 1, 1, 0 }, | |
}; | |
int[,] hConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 1, 1, 1, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
}; | |
int[,] iConfig = new int[,] | |
{ | |
{ 1, 1, 1 }, | |
{ 0, 1, 0 }, | |
{ 0, 1, 0 }, | |
{ 0, 1, 0 }, | |
{ 1, 1, 1 }, | |
}; | |
int[,] jConfig = new int[,] | |
{ | |
{ 0, 0, 1, 1, 1 }, | |
{ 0, 0, 0, 1, 0 }, | |
{ 0, 0, 0, 1, 0 }, | |
{ 0, 0, 0, 1, 0 }, | |
{ 0, 1, 1, 1, 0 }, | |
}; | |
int[,] kConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 1, 0 }, | |
{ 1, 0, 1, 0, 0 }, | |
{ 1, 1, 0, 0, 0 }, | |
{ 1, 0, 1, 0, 0 }, | |
{ 1, 0, 0, 1, 0 }, | |
{ 1, 0, 0, 0, 1 } | |
}; | |
int[,] lConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 1, 1, 1 } | |
}; | |
int[,] mConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 1, 0, 1, 1 }, | |
{ 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 } | |
}; | |
int[,] nConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 1, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 1, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 } | |
}; | |
int[,] oConfig = new int[,] | |
{ | |
{ 0, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 0, 1, 1, 1, 0 } | |
}; | |
int[,] pConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1 }, | |
{ 1, 0, 0, 1 }, | |
{ 1, 0, 0, 1 }, | |
{ 1, 1, 1, 1 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 }, | |
{ 1, 0, 0, 0 } | |
}; | |
int[,] qConfig = new int[,] | |
{ | |
{ 0, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 1 }, | |
{ 1, 0, 0, 1, 1 }, | |
{ 0, 1, 1, 1, 1 } | |
}; | |
int[,] rConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1 }, | |
{ 1, 0, 0, 1 }, | |
{ 1, 0, 0, 1 }, | |
{ 1, 1, 1, 1 }, | |
{ 1, 0, 1, 0 }, | |
{ 1, 0, 0, 1 }, | |
{ 1, 0, 0, 0 } | |
}; | |
int[,] sConfig = new int[,] | |
{ | |
{ 0, 1, 1, 1, 1, 0 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 0 }, | |
{ 0, 1, 1, 1, 1, 0 }, | |
{ 0, 0, 0, 0, 0, 1 }, | |
{ 1, 1, 1, 1, 1, 0 } | |
}; | |
int[,] tConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1, 1, 1 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 } | |
}; | |
int[,] uConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 1, 1, 1, 1, 0 } | |
}; | |
int[,] vConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 1, 0, 0, 1, 0 }, | |
{ 0, 0, 1, 1, 0, 0 }, | |
{ 0, 0, 0, 0, 0, 0 } | |
}; | |
int[,] wConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 1, 0, 1, 0, 0, 1 }, | |
{ 0, 1, 0, 1, 0, 0 }, | |
{ 0, 0, 0, 0, 0, 0 } | |
}; | |
int[,] xConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 1, 0, 0, 1, 0 }, | |
{ 0, 0, 1, 1, 0, 0 }, | |
{ 0, 1, 0, 0, 1, 0 }, | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 0, 0, 0, 0, 0 } | |
}; | |
int[,] yConfig = new int[,] | |
{ | |
{ 1, 0, 0, 0, 0, 1 }, | |
{ 0, 1, 0, 0, 1, 0 }, | |
{ 0, 0, 1, 1, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 0, 0, 0, 0, 0 } | |
}; | |
private int[,] zConfig = new int[,] | |
{ | |
{ 1, 1, 1, 1, 1, 1 }, | |
{ 0, 0, 0, 0, 1, 0 }, | |
{ 0, 0, 0, 1, 0, 0 }, | |
{ 0, 0, 1, 0, 0, 0 }, | |
{ 0, 1, 0, 0, 0, 0 }, | |
{ 1, 1, 1, 1, 1, 1 } | |
}; | |
public int numberOfCubes = 100; | |
public float cubeScale = 0.9f; | |
public float spacing = 0.1f; | |
public GameObject letterPrefab; | |
private Dictionary<char, int[,]> letterConfigs; | |
private void Start() | |
{ | |
letterPrefab = GameObject.CreatePrimitive(PrimitiveType.Cube); | |
letterPrefab.SetActive(false); // Set it to inactive so it doesn't appear in the scene | |
// Initialize the letterConfigs dictionary with all the letters you have | |
letterConfigs = new Dictionary<char, int[,]>(); | |
letterConfigs['a'] = aConfig; | |
letterConfigs['b'] = bConfig; | |
letterConfigs['a'] = aConfig; | |
letterConfigs['b'] = bConfig; | |
letterConfigs['c'] = cConfig; | |
letterConfigs['d'] = dConfig; | |
letterConfigs['e'] = eConfig; | |
letterConfigs['f'] = fConfig; | |
letterConfigs['g'] = gConfig; | |
letterConfigs['h'] = hConfig; | |
letterConfigs['i'] = iConfig; | |
letterConfigs['j'] = jConfig; | |
letterConfigs['k'] = kConfig; | |
letterConfigs['l'] = lConfig; | |
letterConfigs['m'] = mConfig; | |
letterConfigs['n'] = nConfig; | |
letterConfigs['o'] = oConfig; | |
letterConfigs['p'] = pConfig; | |
letterConfigs['q'] = qConfig; | |
letterConfigs['r'] = rConfig; | |
letterConfigs['s'] = sConfig; | |
letterConfigs['t'] = tConfig; | |
letterConfigs['u'] = uConfig; | |
letterConfigs['v'] = vConfig; | |
letterConfigs['w'] = wConfig; | |
letterConfigs['x'] = xConfig; | |
letterConfigs['y'] = yConfig; | |
letterConfigs['z'] = zConfig; | |
DisplayWord("hello",letterConfigs); | |
} | |
public Material cubeMaterial; // Reference to the material to use | |
private void DisplayWord(string word, Dictionary<char, int[,]> letterConfigs) | |
{ | |
cubeMaterial = new Material(Shader.Find("Standard")); | |
cubeMaterial.color = Color.red; // set the material color to red | |
// Check if "Cube" tag exists, and if not, create it | |
if (!TagExists("Cube")) | |
{ | |
AddTag("Cube"); | |
} | |
float x = 0; | |
foreach (char c in word) | |
{ | |
int[,] config = letterConfigs[c]; | |
for (int i = config.GetLength(0) - 1; i >= 0; i--) | |
{ | |
for (int j = 0; j < config.GetLength(1); j++) | |
{ | |
if (config[i, j] == 1) | |
{ | |
GameObject cube = Instantiate(letterPrefab); | |
cube.GetComponent<Renderer>().material = cubeMaterial; | |
cube.transform.localScale = Vector3.one * cubeScale; | |
cube.transform.position = new Vector3(x + j * (cubeScale + spacing), | |
(config.GetLength(0) - i - 1) * (cubeScale + spacing), 0); | |
cube.tag = "Cube"; | |
} | |
} | |
} | |
x += (config.GetLength(1) + 1) * (cubeScale + spacing); | |
} | |
StartCoroutine(ExplodeCubes()); | |
} | |
private IEnumerator ExplodeCubes() | |
{ | |
yield return new WaitForSeconds(3f); | |
GameObject[] cubes = GameObject.FindGameObjectsWithTag("Cube"); | |
foreach (GameObject cube in cubes) | |
{ | |
Rigidbody rb = cube.AddComponent<Rigidbody>(); | |
rb.AddExplosionForce(500f, transform.position, 5f); | |
yield return new WaitForSeconds(0.05f); | |
} | |
} | |
// Helper method to check if a tag exists | |
private bool TagExists(string tag) | |
{ | |
string[] tags = UnityEditorInternal.InternalEditorUtility.tags; | |
for (int i = 0; i < tags.Length; i++) | |
{ | |
if (tags[i] == tag) | |
{ | |
return true; | |
} | |
} | |
return false; | |
} | |
// Helper method to add a new tag | |
private void AddTag(string tag) | |
{ | |
UnityEditorInternal.InternalEditorUtility.AddTag(tag); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment