Say, its a 2D word falling typing game, the words are individual GameObjects. How do I check the y position of each word GameObject falling down the scene and then trigger the Game Over text when it passes a certain y position?
Word GameObject Prefab
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
[System.Serializable]
public class Word {
public string word;
private int typeIndex;
WordDisplay display;
public Word (string _word, WordDisplay _display)
{
word = _word;
typeIndex = 0;
display = _display;
display.SetWord(word);
}
public char GetNextLetter ()
{
return word[typeIndex];
}
public void TypeLetter ()
{
typeIndex++;
display.RemoveLetter();
}
public bool WordTyped ()
{
bool wordTyped = (typeIndex >= word.Length);
if (wordTyped)
{
display.RemoveWord();
}
return wordTyped;
}
void Update()
{
if(Transform.position.y == -328.1865)
{
GameOver.turnon = true;
}
}
}
Event script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GameOver : MonoBehaviour
{
public Text gameOverText;
public static bool turnon;
// Start is called before the first frame update
void Start()
{
gameOverText = GetComponent<Text>();
gameOverText.gameObject.SetActive(false);
turnon = false;
}
void Update()
{
if (turnon == true)
{
gameOverText.gameObject.SetActive(true);
}
}
}