Apply most requested changes
This commit is contained in:
@@ -145,17 +145,27 @@ public class JustSignController : MonoBehaviour
|
||||
currentTheme = FindThemeByName(PlayerPrefs.GetString("themeName"));
|
||||
words = currentTheme.words;
|
||||
lastSpawn = Time.time;
|
||||
Debug.Log("BEFORE");
|
||||
SpawnNewSymbol();
|
||||
Debug.Log("AFTER");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Update is called once per frame
|
||||
/// </summary>
|
||||
void Update()
|
||||
{
|
||||
{
|
||||
int matchedSymbolIndex = -1;
|
||||
for (int i = 0; i < activeWords.Count; i++) {
|
||||
if (activeWords[i] == answerField.text.ToLower()) {
|
||||
matchedSymbolIndex = i;
|
||||
}
|
||||
}
|
||||
|
||||
// Destroy the oldest symbol if the current input matches it
|
||||
if (answerField.text.ToLower() == activeWords[0]) {
|
||||
int difference = Math.Abs((int) (activeSymbols[0].transform.position.x - hitZone.transform.position.x));
|
||||
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;
|
||||
@@ -170,14 +180,16 @@ public class JustSignController : MonoBehaviour
|
||||
score += terribleScore;
|
||||
}
|
||||
|
||||
DestroyRightmostSymbol();
|
||||
DestroySymbolAt(matchedSymbolIndex);
|
||||
answerField.text = "";
|
||||
}
|
||||
|
||||
// Destroy the oldest symbol if it leaves the screen
|
||||
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX) {
|
||||
DestroyRightmostSymbol();
|
||||
score += offscreenScore;
|
||||
if (activeSymbols.Count > 0) {
|
||||
if (activeSymbols[0].GetComponent<RectTransform>().localPosition.x > -trackX) {
|
||||
DestroySymbolAt(0);
|
||||
score += offscreenScore;
|
||||
}
|
||||
}
|
||||
|
||||
// Spawn new symbol every spawn period
|
||||
@@ -197,12 +209,13 @@ public class JustSignController : MonoBehaviour
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroy the oldest symbol on the track
|
||||
/// Destroy the symbol at the given index
|
||||
/// </summary>
|
||||
void DestroyRightmostSymbol() {
|
||||
activeWords.RemoveAt(0);
|
||||
GameObject symbol = activeSymbols[0];
|
||||
activeSymbols.RemoveAt(0);
|
||||
/// <param name="index">The index of the symbol to destroy</param>
|
||||
void DestroySymbolAt(int index) {
|
||||
activeWords.RemoveAt(index);
|
||||
GameObject symbol = activeSymbols[index];
|
||||
activeSymbols.RemoveAt(index);
|
||||
Destroy(symbol);
|
||||
}
|
||||
|
||||
@@ -233,21 +246,106 @@ public class JustSignController : MonoBehaviour
|
||||
/// Create a new symbol at the start of the track
|
||||
/// </summary>
|
||||
void SpawnNewSymbol() {
|
||||
string nextSymbol = words[UnityEngine.Random.Range(0, words.Length)];
|
||||
List<int> unusedWordIndices = new List<int>();
|
||||
|
||||
for (int i = 0; i < words.Length; i++) {
|
||||
if (!activeWords.Contains(words[i])) {
|
||||
unusedWordIndices.Add(i);
|
||||
}
|
||||
}
|
||||
|
||||
string nextSymbol = words[unusedWordIndices[UnityEngine.Random.Range(0, unusedWordIndices.Count)]];
|
||||
|
||||
GameObject newSymbolObject = new GameObject("Symbol");
|
||||
Image newImage = newSymbolObject.AddComponent<Image>();
|
||||
RectTransform rectTransform = newSymbolObject.GetComponent<RectTransform>();
|
||||
|
||||
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);
|
||||
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 new sprite as the Image component's source image
|
||||
newImage.sprite = sprite;
|
||||
// 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;
|
||||
|
||||
|
||||
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