Script to make 3D text disappear based on player position

What I am trying to do is to make a 3D text appear when I reach past a certain point on my environment. Specifically, I want the text to appear when I enter a doorway but disappear when I am outside the building. Since the player is basically moving in a straight line up to the door frame I figured the only thing I needed to consider was the x-coordinate (in this case -19). But I can’t make this script I’ve been playing around work; it either makes the text completely disappear or stay the entire time. I can’t tell where I’m wrong but any help would be greatly appreciated. Thanks!

using UnityEngine;
using System.Collections;

public class TextTest : MonoBehaviour 
{
public GameObject Player;
public GameObject Text;



	// Use this for initialization
	void Start () 
	{Text.SetActive(false);
		
		
		if 
			(Player.transform.position.x>-19f)
		
		{Text.SetActive(true);
		
		}
	}
	

	
	// Update is called once per frame
	void Update () {

	}
}

Your position check should be inside your Update method as the Start method will only get called once

I’ve tried that but it didn’t make a difference…

You definitely need to move the code into Update() method. After that try to see if you are getting inside the if-block (either debug or print something out). If you are getting inside then something is wrong with your Text GameObject. If you are not getting inside then something wrong with your assumption that x-coord has to be greater than -19. Also keep Text.SetActive(false); in a Start() method and change your Update code to look like:

if (Player.transform.position.x>-19f)
{
	Text.SetActive(true);
}
else
{
	Text.SetActive(false);
}

I tried printing something from inside the if statement to see if it worked but apparently I’m not getting in it. I tried it with your code as well but didn’t help. One thing is I have the player set to the FirstPersonController; so when it changes position it’s suppose to activate the script. I didn’t think that would be a problem but would it? Thanks for the help

Alright, just an update on this: I figured out the code to make it work so that when I reach a specific point the text will appear or disappear. Wasn’t very hard; I have the scripts attached to the FirstPersonController and the text. Just thought I’d include the code in case anyone was interested (probably not lol)

using UnityEngine;
using System.Collections;

public class Phase1Text : MonoBehaviour 
{
public GameObject Player;
public GameObject Text;



	// Use this for initialization
	void Start () {
	}

	
	// Update is called once per frame
	void Update () {
		
	if (((Text.transform.position.x)-(Player.transform.position.x)) < 12f)
		
		{	Text.SetActive(true);
		
		}
		else{
			Text.SetActive(false);
		}
	}
}