- Home /
Why is my code deleting my particle emitter?
I wrote a simple code to check the distance of an object and the camera and then change the emission level of a flame emitter, but after I get a certain distance from it, it automatically deletes the game object that has the emitter and code in it. Attached is the editor area of unity and the code I am using.
var target: Transform;
function Update () {
var dist : float = Vector3.Distance(target.position, transform.position);
if(dist <= 13){
particleEmitter.maxEmission = 100;
}else{
particleEmitter.maxEmission = 0;
}
}
edit: think I found a fix. It does not like me to use the number 0, it thinks I just want it deleted, now I need to find a number small enough for it to no longer shoot puffs of flames.
edit: only works temporaly, i changed the code and it still seems to want to happen, if I remove the code it stops having the problem. new code:
var target: Transform;
function Update () {
var fwd = transform.TransformDirection (Vector3.forward);
var dist : float = Vector3.Distance(target.position, transform.position);
if(dist <= 13 /*&& !Physics.Raycast (transform.position, fwd*/){
/*particleEmitter.maxEmission = 100;*/
}else{
/*particleEmitter.maxEmission = .0001;*/
}
}
edit: should be the final one, code is now: var target: Transform; function Update () { //var fwd = transform.TransformDirection (Vector3.forward); var dist = Vector3.Distance(target.position, transform.position);
if(dist <= 13){
particleEmitter.emit = true;
}else{
particleEmitter.emit = false;
}
}
bug still happens, but if code is changed to:
var target: Transform;
function Update () {
//var fwd = transform.TransformDirection (Vector3.forward);
var dist = Vector3.Distance(target.position, transform.position);
if(dist <= 13){
particleEmitter.emit = true;
}else{
particleEmitter.emit = ***true***;
}
}
the problem stops
Are you sure that is the only code referencing your emitter object. Simply that line won't delete the object. Double check any reference your your object to check that something else isn't destroying it. Should still be alive.
there is noting else attached to it, the only other script is just a transform.lookat code. Its gameobject does slide in an animation though. It seems to happen when I move into the 13 unit field and then back out of it. Not sure though.
nope, I cannot find a gameobject.destroy, i will check again though. It is just a standard asset with a added code and a changed parameters.
it actually happens whenever I am more than 13 unity away.
Your answer
Follow this Question
Related Questions
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Detect when instance has deleted 0 Answers
Laser Beam in Unity 0 Answers
Resetting non-looping particle system 5 Answers