hello all. i need help for a simple problem, but might require long explanation. programm
i've created a text object that is the letter E that pops up whenever the player gets close to an NPC. it works, but the letter stays there forever.
at first i've created (based on some tutorial) a destroy command, but once it's destroyed it won't reappear, even though i've used a method with “Instantiate” and even though it's placed in the update method.
i simply would like to know what lines of code i should put where, and of course an explanation about them, to make the object disappear when outside the trigger zone (which is based on box colliders) and reappear when the player gets back.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WomanNPC : MonoBehaviour
{
public GameObject FloatingTextPrefab;
private GameObject triggeringPlayer;
private bool triggering;
private GameObject myE;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
if (triggering)
{
if (FloatingTextPrefab)
{
ShowFloatingText();
}
}
else
{
ShowFloatingText(false);
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "Player")
{
triggering = true;
triggeringPlayer = other.gameObject;
}
}
void OnTriggerExit(Collider other)
{
if (other.tag == "Player")
{
triggering = false;
triggeringPlayer = null;
}
}
void ShowFloatingText()
{
Instantiate(FloatingTextPrefab, transform.position, Quaternion.identity, transform);
}
void HideFloatingText()
{
Destroy(FloatingTextPrefab);
}
}
this is the NPC's code, on which is based the floating text object for it's location purposes. right now the “else” method obviously's not working, as well as the “HideFloatingText” method i've tried to make.
thanks!