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.
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
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.
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
The way that ande04b described above would be more ideal, instead of instantiating the textObject just use gui functions