My player has a spherical trigger on him. I need a script that makes it so when my player’s trigger gets close to any gameobject tagged Character, then a GUI window pops up, something like this:
function OnTriggerEnter() {
if gameObject I collided with tag is Character;
then
make a GUI Window
with text in it.
Something like that, see. If it’s not possible to do it with a trigger then I could also use distance but I’m not sure how to do that and I would prefer to use a trigger.
My goal is that I want to have a sort of character interaction, where one character can go up to another character and talk to him, and the other character will give the main character some advice, or ask him a question or such.
Thanks
A good first, for you is… have you ever successfully used OnTrigger functions. So far the way that I have gotten OnTrigger (enter/stay/exit) to work was this:
MainCharObject was given x-Collider and a Rigidbody. TargetObject was given x-Collider which I set to IsTrigger, and a script with OnTriggerStay. This was meant to destroy it self as it hit my character. (x-Collider being any collider you need).
void OnTriggerStay(Collider target)
{
if(target.tag == "Player")
{
Destroy(this.gameObject);
}
}
Even though this is C# you should be able to get a sense of it, and use OnTriggerEnter() Documentation to change what you need.
You should also easily be able to swap which object keeps the script, and IsTrigger. The object that is not IsTrigger, will need a Rigidbody. However not excluding the one which Istrigger from having one, as far as I know.
Hope you can use this.