Materialize an object, then destroy it.

I need an object to appear as player walks into a trigger. So basicly I am asking for just one line of a script to make an object materialize in front of a player and then to be destroyed. Here is a reference to what I want to achieve.

public var AnObject : GameObject;

function OnTriggerEnter(other : Collider){
    if(other.gameObject.name == "Player"){
         ------------------------????
         yield WaitForSeconds(3);
         GameObject.Destroy(AnObject);
    }
}

Set the renderer.enabled to false in the inspector, then you can do: renderer.enabled = true;

Here is the script. Shows no errors. However doesn't work. #pragma strict public var AmbienceCrate : GameObject; function Awake (AmbienceCrate) { renderer.enabled = false; } function OnTriggerEnter(other : Collider){ if(other.gameObject.name == "Player"){ renderer.enabled = true; yield WaitForSeconds(3); GameObject.Destroy(AmbienceCrate); } }

1 Answer

1

The following should be an excellent read for you:

I sure will but it would be nice to get an answer as well as a direction in which to move. Thanks thou.

I got it! Here is a working script! Thank you so much. public var AmbienceCrate : GameObject; function Start () { AmbienceCrate.SetActive(false); } function OnTriggerEnter (Col : Collider) { if(Col.tag == "Player") { AmbienceCrate.SetActive(true); yield WaitForSeconds(3); GameObject.Destroy(AmbienceCrate); } }

I'm glad you got it working. Just keep in mind that you are disabling the entire GameObject, which may or may not be exactly what you want.

I'm pretty sure it's fine for me. I only need it to appear once and won't need it anymore.