GUItexture did not disappear after 10 seconds

HELP !! my defense is on friday but my game does not totally work.

i destroy the object then GUItexture will appear but i want after 10 seconds the GUITexture will disappear. Please i need help …
thank you so much.

function OnTriggerEnter (other : Collider) {

    Destroy(gameObject);
    gameObject.Find("balisong").GetComponent("GUITexture").enabled = true;
} 

IEnumerator ShowGuiTexture(balisong, 10 )

{

  if( balisong == null )

    yield break;

  GUITexture.enabled = true;

  yield return new WaitForSeconds( 10);

   GUITexture.enabled = false;

}

1 Answer

1

Ok, sorry to say this, but your code is nonsense. Here’s what I would do:

function OnTriggerEnter() {
    destroy(gameObject);
    GameObject.Find("balisong").GetComponent("GUITexture").enabled = true;
     GameObject.Find("balisong").GetComponent.<TextureFlashScript>().Invoke("HideGUI", 10);
}

To elaborate on the, err..."nonsense," OnTriggerEnter is written in javascript, but IEnumerator is for C#. You forgot to RUN the ShowGUITexture function. You could use StartCoroutine(ShowGUITexture); But, Invoke is a shortcut if you just want to delay something (which, in this case, you do.) Lastly, I believe that when you destroy yourself, you also destroy your coroutines. In that case, you'd want to put the "hide then show" function on your balisong (and not in the guy who's dieing.)

@Owen Reynolds, I was thinking that last bit too; I just couldn't remember for sure when I was answering the question. So here's a little change that should fix it.