- Home /
Particle system turns on when player gets close.
I need help with turning on a particle system when the player gets close to it. I also need it to turn off when the player is out of its radius. javascript is how I am writing the code. I currently don't have a script written yet.
Answer by hijinxbassist · May 25, 2012 at 05:46 AM
You will be using distance in an if conditional or use an isTrigger collider to trigger the event.
On particle systems gameObjects script
if( (player.transform.position-transform.position) <= desiredDistance )
{
//Start emission
}
or with the trigger (This trigger is on the particle systems gameObject)
function OnTriggerEnter(other:Collider)
{
if(other.tag == "Player")
{
//Start emission
}
}
function OnTriggerExit(other:Collider)
{
//End emission
}
The preferred method would be the latter using the trigger. It will be more efficient since the cpu will not need to continually calculate the distance between the particle system and the player. Let me know if you need help setting it up.
Your answer
Follow this Question
Related Questions
particle emitter on/off using the left mouse button 1 Answer
Particle on and off 1 Answer
Multiple Save (Saving & Loading System) With PlayerPrefs 2 Answers
turn on and off the render of a child 1 Answer
Enable and Disable a script 1 Answer