Text Pop Up on Trigger

Okay, so here’s my situation. I know 0% of anything to do with scripting. I have just started.

However, I need help with this.

I want my player to enter a box collider and upon entering the box collider, the gameobject that hosted the collider gets destroyed and text pops up on the screen(initially meant to be my character’s dialogue), then this this dialogue goes away about 5 seconds after popping up.

Anybody can simply teach me how to do this? I have tried so many ways, every script I use, it has a form of error within, there’s barely any tutorials and I am desperate for help.

Why not try to fix the errors with the methods you have already tried?

Exit trigger: Unity - Scripting API: Collider.OnTriggerExit(Collider)
Destroying: Unity - Scripting API: Object.Destroy
Instance a text: Unity - Scripting API: Object.Instantiate
Using text: Unity - Manual: Text Mesh component (legacy)

No.
beginner tutorials: http://www.unity3dstudent.com/

Hmfph, I really understood none of it.

I’m a beginner, is there any way I can understand this learn, in a simpler manner?

I dunno man, these are pretty much as basic as it gets, and it even goes through it step by step
Unity 3D Student - 3d Modelling (in case you couldnt find the list)

You should look into a function called OnTriggerEnter, and also at a function called OnGUI :slight_smile:

OnTriggerEnter is a funciton that checks for collision between 2 objects, and performs an action upon it.
OnGUI is basically a function used to display stuff like textures or text on screen without it having to be
attached to an object of some kind.

If you need more help, feel free to ask. :slight_smile:

First you need to check out the documentation on Physics Components as you will need colliders and Rigidbodies. http://docs.unity3d.com/Documentation/Components/comp-DynamicsGroup.html

Then you need to setup your player, the collider/object that spawns the pop-up, and create the pop-up graphic itself and setup a prefab that contains it.

Then check out tiny bit of code and try to understand what its doing, how its working with all the objects involved and look everything up in the scripting reference. Unity - Scripting API:

Next you can make a simple script to attach to the game object and destroy it. (should only take 3 short lines to do)

var textObject : GUITexture;                                                       //The game object to spawn



function OnTriggerEnter(  otherObject: Collider  ){                              //This object makes contact with another objects collider

if(otherObject.gameObject.tag == "Player"){                                         //The other objects is tagged as player
Instantiate(textObject, Vector3(.5, .5, 0.0), Quaternion.identity);         //spawn textObject var from above
Destroy(gameObject);                                                                           //destroy object/collider this script is attached to


}
}

This may not be the best way but its simple and works for me :slight_smile:

The way that ande04b described above would be more ideal, instead of instantiating the textObject just use gui functions