- Home /
Object Disappearing when comes close to player.
Hello. I need your guys help. Well... i have made a zombie model, and all it's animations are done. But i want a zombie to run up to me, then it quickly disappears into like a smoke particle effect. So basically when the zombie is in like a 2 meters range of the player it will disappear. I'm okay with some code, i'm just new to Unity. Sorry. But if you could just give me an example of how to do this, it would be great.
Thanks ! #Swifted
You mark an answer as correct by clicking the checkmark, not by writing "solved" in the title.
Answer by Cool Dave · Sep 17, 2012 at 06:45 PM
Attach a JavaScript Script to your player with this code. Welcome to the forums, and be sure to mark this answer as correct if it solves your problem.
var zombieT : Transform;
var zombie : GameObject;
var vanishDist = 2.00;
function FixedUpdate ()
{
if (zombie)//If he still exists
{
var dist = Vector3.Distance(zombieT.position, transform.position);//How far is he
if (dist < vanishDist)//If he is close enough
{
Destroy (zombie);//Make him disappear
}
}
}
I changed the code a bit because there was a problem in it. And as Eric said, please hit the checkmark on my answer.
It doesn't look like you've checkmarked it. Or have you?
He hasn't. Also please don't post comments as answers, Swifted (I converted the answer to a comment).
On the left side, under the vote buttons next to the answer.
Your answer
Follow this Question
Related Questions
Opening a door at proximity 2 Answers
Can i add texture to multiple layers of player? and how? 0 Answers
Activate a Object 1 Answer
Audio Plays when close to player 1 Answer