I am having trouble destroying or removing the GUI/Text/Picture etc after it runs so that I can go into next scene.
Here’s what I have tried doing but is not working. pelase tell me if I am on wrong track as I am new to Unity.
I’ve attached a Box Collider to an object 3d , then dragged a script that I’ve written as follows:
function OnGUI ()
{
function OnTriggerEnter()
{
GUI.DrawTexture (Rect (0, 0, screenwidth, screenheight), textureBackground2, ScaleMode.StretchToFill);
GUILayout.Label("texthere");
.... so on
}
}
after i run the game player it displays the object 3d display text like “texthere”,but player goes someplace does not destroy the texthere.in this i want to player collide the object 3d and display some gui and whencollide is completed i want destroy the gui msg.
The script you’ve posted won’t compile and you will certainly be getting error messages about this. You can’t declare one function inside another but you can use a boolean flag to pass the state of the collision on to the OnGUI function:-
var colliding: boolean;
function OnCollisionEnter(col: Collision) {
colliding = true;
}
function OnCollisionExit(col: Collision) {
colliding = false;
}
function OnGUI() {
if (colliding) {
GUI.DrawTexture(...);
// etc...
}
}
Thanks for the help chaps.Now it is works.
I have done the same thing but still it does not works so i am attaching my script here
Code:
private var isGuiEnable : boolean;
var l_name: String = “”;
var f_name: String = “”;
function OnMouseDown()
{
if(gameObject.name == “Registration”)//a 3D text used as button
{
isGuiEnable = true;
}
if(gameObject.name == “Ok”)//a 3D text used as button
{
isGuiEnable = false;
}
}
function OnGUI()
{
if(isGuiEnable)
{
f_name = GUI.TextArea(Rect(275,34,230,30),f_name);
l_name = GUI.TextArea(Rect(275,70,230,30),l_name,15);
}
}
Welcome to the forum, satanicrohan!
The OnMouseDown and OnMouseUp functions will only be called if the script is attached to the object that is clicked and then only if that object also has a collider. You will probably find it easier to detect the object under the mouse using a raycast as explained in this thread.
thanks…
but finally got it…
i created one script for OnGUI() and another for Registration and ok object
attached ongui script to camera and used a boolean to turn it on and of using GetComponent.
thanks a lot…