Add words to symbols in JustSign
This commit is contained in:
@@ -35,6 +35,16 @@ public class JustSignController : MonoBehaviour
|
||||
/// </summary>
|
||||
public GameObject hitZone;
|
||||
|
||||
/// <summary>
|
||||
/// Symbol prefab
|
||||
/// </summary>
|
||||
public GameObject symbolPrefab;
|
||||
|
||||
/// <summary>
|
||||
/// Reference to symbol prefab
|
||||
/// </summary>
|
||||
public Transform symbolContainer;
|
||||
|
||||
/// <summary>
|
||||
/// All of the words that can be used in this session
|
||||
/// </summary>
|
||||
@@ -145,9 +155,7 @@ public class JustSignController : MonoBehaviour
|
||||
currentTheme = FindThemeByName(PlayerPrefs.GetString("themeName"));
|
||||
words = currentTheme.words;
|
||||
lastSpawn = Time.time;
|
||||
Debug.Log("BEFORE");
|
||||
SpawnNewSymbol();
|
||||
Debug.Log("AFTER");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -165,7 +173,6 @@ public class JustSignController : MonoBehaviour
|
||||
// Destroy the oldest symbol if the current input matches it
|
||||
if (matchedSymbolIndex >= 0) {
|
||||
int difference = Math.Abs((int) (activeSymbols[matchedSymbolIndex].transform.position.x - hitZone.transform.position.x));
|
||||
Debug.Log("HERE");
|
||||
if (difference < perfectBoundary) {
|
||||
feedBack.text = "Perfect!";
|
||||
score += perfectScore;
|
||||
@@ -246,6 +253,7 @@ public class JustSignController : MonoBehaviour
|
||||
/// Create a new symbol at the start of the track
|
||||
/// </summary>
|
||||
void SpawnNewSymbol() {
|
||||
// Pick a word that isn't in use yet
|
||||
List<int> unusedWordIndices = new List<int>();
|
||||
|
||||
for (int i = 0; i < words.Length; i++) {
|
||||
@@ -256,96 +264,21 @@ public class JustSignController : MonoBehaviour
|
||||
|
||||
string nextSymbol = words[unusedWordIndices[UnityEngine.Random.Range(0, unusedWordIndices.Count)]];
|
||||
|
||||
GameObject newSymbolObject = new GameObject("Symbol");
|
||||
|
||||
RectTransform rectTransform = newSymbolObject.AddComponent<RectTransform>();
|
||||
|
||||
// Add the Image component as a child of the RectTransform
|
||||
Image image = new GameObject("Image").AddComponent<Image>();
|
||||
image.transform.SetParent(rectTransform);
|
||||
|
||||
// Add the Text component as a child of the RectTransform
|
||||
Text text = new GameObject("Text").AddComponent<Text>();
|
||||
text.transform.SetParent(rectTransform);
|
||||
|
||||
// Set the font size of the text component
|
||||
text.fontSize = 100;
|
||||
text.text = "AAAAAAA";
|
||||
text.color = Color.white;
|
||||
|
||||
rectTransform.SetParent(canvas.transform, false); // Set the parent to the Canvas
|
||||
rectTransform.localPosition = new Vector3(trackX, trackY, 0);
|
||||
rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize + 200f);
|
||||
GameObject newSymbolObject = GameObject.Instantiate(symbolPrefab, symbolContainer);
|
||||
|
||||
// Dynamically load appearance
|
||||
Image image = newSymbolObject.GetComponent<Image>();
|
||||
Sprite sprite = Resources.Load<Sprite>("Common/Images/" + nextSymbol);
|
||||
image.sprite = sprite;
|
||||
image.rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize);
|
||||
|
||||
// Set the position and size of the RectTransform of the text component to match the RectTransform of the image component
|
||||
text.rectTransform.localPosition = new Vector3(0, -50, 0);
|
||||
text.rectTransform.sizeDelta = rectTransform.sizeDelta;
|
||||
|
||||
// Place the word that the symbol represents under the image
|
||||
TMP_Text text = newSymbolObject.GetComponentInChildren<TMP_Text>();
|
||||
text.text = nextSymbol;
|
||||
text.color = Color.black;
|
||||
text.rectTransform.localPosition = new Vector3(0, -160, 0);
|
||||
|
||||
activeWords.Add(nextSymbol);
|
||||
activeSymbols.Add(newSymbolObject);
|
||||
}
|
||||
|
||||
/*
|
||||
GameObject newSymbolObject = new GameObject("Symbol");
|
||||
Image image = newSymbolObject.AddComponent<Image>();
|
||||
Sprite sprite = Resources.Load<Sprite>("Common/Images/" + nextSymbol);
|
||||
image.sprite = sprite;
|
||||
//Text text = newSymbolObject.AddComponent<Text>();
|
||||
//text.text = "METTN";
|
||||
RectTransform rectTransform = newSymbolObject.GetComponent<RectTransform>();
|
||||
rectTransform.SetParent(canvas.transform, false); // Set the parent to the Canvas
|
||||
rectTransform.localPosition = new Vector3(trackX, trackY, 0);
|
||||
rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize);
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
GameObject newSymbolObject = new GameObject("Symbol");
|
||||
Image newImage = newSymbolObject.AddComponent<Image>();
|
||||
Text text = newSymbolObject.AddComponent<Text>();
|
||||
RectTransform rectTransform = newSymbolObject.GetComponent<RectTransform>();
|
||||
rectTransform.SetParent(canvas.transform, false); // Set the parent to the Canvas
|
||||
rectTransform.localPosition = new Vector3(trackX, trackY, 0);
|
||||
rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize);
|
||||
*/
|
||||
|
||||
/*
|
||||
GameObject newSymbolObject = new GameObject("Symbol");
|
||||
|
||||
RectTransform rectTransform = newSymbolObject.AddComponent<RectTransform>();
|
||||
|
||||
// Add the Image component as a child of the RectTransform
|
||||
Image image = new GameObject("Image").AddComponent<Image>();
|
||||
image.transform.SetParent(rectTransform);
|
||||
|
||||
// Add the Text component as a child of the RectTransform
|
||||
Text text = new GameObject("Text").AddComponent<Text>();
|
||||
text.transform.SetParent(rectTransform);
|
||||
|
||||
// Set the font size of the text component
|
||||
text.fontSize = 30;
|
||||
text.text = "AAAAAAA";
|
||||
text.color = Color.black;
|
||||
|
||||
Sprite sprite = Resources.Load<Sprite>("Common/Images/" + nextSymbol);
|
||||
|
||||
|
||||
|
||||
rectTransform.SetParent(canvas.transform, false); // Set the parent to the Canvas
|
||||
rectTransform.localPosition = new Vector3(trackX, trackY, 0);
|
||||
rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize + 200f);
|
||||
|
||||
Sprite sprite = Resources.Load<Sprite>("Common/Images/" + nextSymbol);
|
||||
image.sprite = sprite;
|
||||
image.rectTransform.sizeDelta = new Vector2(symbolSize, symbolSize);
|
||||
|
||||
// Set the position and size of the RectTransform of the text component to match the RectTransform of the image component
|
||||
text.rectTransform.localPosition = new Vector3(0, -50, 0);
|
||||
text.rectTransform.sizeDelta = rectTransform.sizeDelta;
|
||||
*/
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user