- Home /
how to make an enemy appear then disappear. (if possible with audio)
Hi, this is my second question, I am currently creating my first horror game, but now I need help. I don't know how to make an enemy appear then disappear, in other words, I don't know the script. Please tell me how and if you do give a script please tell me the type. Oh and also, if possible, can an audio be inserted with the character everytime it Appears? Thank you. I will be sure to add you to the credits.
Appear when you enter a trigger, randomly, or...?
This one deals with triggers and jumpscares:
Any, just tell me what to do then the script, oh, leave your name too so that you can be in the credits
Answer by Commander Quackers · Dec 15, 2013 at 07:34 AM
Here, just made this, tested and it works: [It's javascript]
function OnTriggerEnter (other : Collider){
if (other.gameObject.tag == "Player") {
renderer.enabled = true;
yield WaitForSeconds(2);
renderer.enabled = false;
}
}
To use it, attach this to your enemy, and make sure you have a collider (a box collider works best) and check "Is Trigger." When your player enters the box collider, the enemy will appear for 2 seconds and then disappear. You can change the time in WaitForSeconds(); to whatever you like.
You don't need to add me to the credits
Oh and for the audio just put "var sound : AudioSource; at the top of the script, and right before the line
renderer.enabled = true;
put in this line
sound.Play();
and you should be good to go, just add an audiosource to the enemy object with the sound you want
I have writtn down the script, its ok. But now, I attached it to the zombie $$anonymous$$odel and a message says "There is no renderer attached to the zombie game object, but a script is trying to access it." Please help
var zr : Renderer;
drag the appropriate renderer to the slot in the inspector.
then, ins$$anonymous$$d of renderer.enabled
, you can say zr.enabled
.
But then where do I find the renderer (sorry I am completely new)
Somewhere in the zombie's hierarchy is an object that has a mesh renderer and a mesh filter component. It's not the root (main game object) or renderer.enabled would not throw an error. The object with the mesh renderer on it is what you need to drag to the zr
slot in the inspector.
Your answer
Follow this Question
Related Questions
touch appear let go dissapear? 2 Answers
Materialize an object, then destroy it. 1 Answer
Making an object blinking for some time, then dissapearing 2 Answers
Object Apear WaitForSeconds Disappear 1 Answer
Downsize A 3DS Model? 1 Answer