- Home /
how to add time ? (how to show a guiTexture and hide it after some time?)
good day !! ..help please .. how to add time when the character destroy the object ..
function OnTriggerEnter (other : Collider) { Destroy(gameObject); gameObject.Find("balisong").GetComponent("GUITexture").enabled = true; }-this is my code when i destroy the object. Where i place the code of adding time . and how? thank you so much
COMMENTS POSTED AS ANSWERS AND MOVED HERE/DELETED (by aldonaletto):
1- thankyou ! i'll try it :)
2- how to disapper the guitexture after seconds. ? not the gameobject ..
3- how to disappear the GUITexture when the gameobject destroy? for example .. when the character destroy the object the guitexture will appear but after 5 seconds the guitexture will disappear .. thx ..!
@larrielyn, I edited my answer to show how to get the expected result. I also edited the question and added the comments/replies you've posted as answers, and deleted that answers. UA works is not like forums: the answer box should be used only to answer your question, while comments, replies etc should be posted with the button add new comment (I know, nobody told you that before...)
Answer by aldonaletto · Sep 10, 2011 at 04:15 AM
Add time to what? If you want to delay the object destruction, you can use something like this:
Destroy(gameObject, 5); // destroy after 5 seconds
EDITED: Ok, so you want to enable the GUITexture and disable it after some delay. The best alternative is to create a function in the "balisong" object, and modify the script below to call it. Let's suppose the script attached to balisong is called BalisongScript.js (change the GetComponent argument if the script has a different name):
function OnTriggerEnter (other : Collider) { Destroy(gameObject); // call the function Show in the BalisongScript.js GameObject.Find("balisong").GetComponent(BalisongScript).Show(); }In the balisong object, add the code below to its script - or create a new script, if it has none:
function Show() { guiTexture.enabled = true; // enable the guitexture yield WaitForSeconds(5); // 5 seconds delay guiTexture.enabled = false; // disable guiTexture }
NOTE: The Your Answer box must be used only to post answers to your question - use the minuscule add new comment button in the question or answers to post replies or comments.
sorry for being naughty ..I did, what you told but this line says that cannot be assigned to. i create BalisongScript.js then attach it in GUItexture but does not work . sorry again :(
GameObject.Find("balisong").GetComponent(BalisongScript).Show() = true; }
I tested the scripts above, and they worked fine. Let's check if the sequence is ok:
1- I attached the first script to the trigger object;
2- I created a GUITexture and named it "balisong";
3- I attached the BalisongScript.js to the balisong object;
Did you do the same? If you got any error, post it here.
NOTE: I've just found an error in the trigger script above: I forgot "= true" after "GetComponent(...).Show()" when I edited the answer. Now I fixed the answer, and it should work as in my tests.
suppose to be this .. right?
GameObject.Find("balisong")=true.GetComponent(BalisongScript).Show();
}
i found the error again says "cannot be assigned to"
No, there's no '=true' in this line - I didn't make myself clear, I suppose. You can copy the script from my answer now - I already fixed it.
Your answer
![](https://koobas.hobune.stream/wayback/20220612210220im_/https://answers.unity.com/themes/thub/images/avi.jpg)