|
i am trying to make a script that makes text appear when you move next to an object. i have used the GUI text but i want it to appear when you move close to an object and dissapear when you move away from the object. is it possible to do this? please help thanks.
(comments are locked)
|
|
Yes, that's possible. Here's what you do (assuming you are using JS). Create a sphere gameobject, and set it's collider to
Next, create another script, and put it on your main character:
Now, if your player enters the trigger you made, it will set a boolean variable inside your player script to 'true'. If the value is true, then a GUI text field will appear. Hope this helps! EDIT: If it's still not working, go over this list, making sure they are all right.
ANOTHER EDIT: Set your trigger's code to this:
Hmm. I really can't see anything else that's wrong in my instructions... It all should work. Try one more time, except replace the old trigger code with this above code. Also, recopy the player's code, I made a couple of changes. do you add the second script to the first person controller or to an object? thanks.
Mar 30 '10 at 04:13 PM
rahib
You add it to the first person controller(main character, I called it)
Mar 30 '10 at 04:17 PM
e.bonneville
does'nt seem to work :(. do i need to create GUI text?
Mar 30 '10 at 04:32 PM
rahib
Hmm. Make sure your first person controller's tag is player. Maybe I've got a typo. I'll go over it again.
Mar 30 '10 at 04:39 PM
e.bonneville
yeah ive done evrything you've said except now when i walk into trigger the game pauses.
Mar 30 '10 at 04:59 PM
rahib
(comments are locked)
|
|
Elbon96 did a fantastic job here. Addition is that the Sphere Object needs to be a child of your main character's object, so that the "SendMessageUpwards()" can be received.
(comments are locked)
|
|
you need to creat a sphere collider (compomponent> physics> sphere collider. whn the object Selected) set it to "is trigger". Then Attach this code to the player: var displayMessage = false; function OnTriggerEnter (other : Collider) { displayMessage = true; } *javascript this code Does that any trigger you go to, It writes "hllow world" if you want its for Specific object I think you need to Write: function OnTriggerEnter (other : Collider "object name") {
(comments are locked)
|
