I have a game object, and I would like it to disappear and be replaced with a particle system. I have a script ( see below) which does not have any errors in, but when the player runs into the present, nothing happens.
I need this to work, and i need it to work soon ( alpha deadline is less than a month away ) but i cannot get this script to function correctly.
Here is the script:
var FinalEffect : GameObject;
function OnTriggerEnter (other : Collider)
{
if ( other.name=="Player")
{
Instantiate (FinalEffect);
Destroy (this.gameObject);
}
}
can anyone help?
Thanks
-Mike
What object is the script attached to? The player? The ‘present’? Something else?
the script will be attached to the present.
basically, when the player runs into the present, i want the present to disappear and be replaced with a particle system i have set up 
The script will be attached to the present, or the script is attached to the present? Because if it’s not attached to the present currently, that’s probably part of the problem 
If it is attached to the present, try printing out ‘other.name’ in OnTriggerEnter using Debug.Log() to see if it has the value you’re expecting. (Another option would be to tag the player as ‘Player’ and check the tag instead.)
Also, what are the ‘Present’ and ‘Player’ variables for? You don’t appear to be using them in your code (at least not in what you posted).
ok, i have edited out the 2 variables at the start ( they are for later on after i have gotten this bit sorted, but i can add them in then) and i already had the script attached to the present 
it still does not work 
Both the present and the player have colliders, and the present has trigger ticked on it’s collider ( player doesn’t )
do see any way i could get this working as it should?
-Mike
EDIT
ok, I have the collision sorted, but it wont do the final effect. How would i get it to do the effect?
well, i did a similar thing , and i noticed that OnTriggerEnter() sometimes gives problems , so i used instead OnTriggerStay() and it is more effective , try it and it should work .
And about the FinalEffect , i advise u to put a prefabs that contain both ur present object and the particles object , but turn the particles renderer to false , it means it will not appear even if it is here, when the collision happend, swap between them , hide the visible one wich is the present, that unhide the particle, use “yield WaitForSeconds()” to hold on the particle for a while then destroy evrything.
use :
renderer.enabled = false; // or true ofc
Are you getting any error messages?
crazyosachou - thanks dude 
could you show me what you mean?
I am kinda lost 
Jesse - nope. no error messages 
put ur present object in the scene, that create a particle at the same position, set up ur particles that will look as u want then make it child of ur presents object , so we have ==> presentObject parent of the particle.
Uncheck now the Particle R enderer, u’ll notice that the particle is not visible anymore, even if it 's in the scene.
(we suppose that ur script is added to the present object)
no here is the code :
var FinalEffect : GameObject;
function OnTriggerEnter (other : Collider)
{
if ( other.name=="Player")
{
renderer.enabled = false ; // make the present object invisible
collider.isTrigger = true; // disable the collider to avoid any bug
FinalEffect.renderer.enabled = true ; // make the particle visible
yield WaitForSeconds(3); //wait a while,for 3 seconds in this example before destroying
Destroy(this.gameObject); // Destroy the present and since the particle is a child of it , it will be destroyed as well
}
} // You can add a sound effect as well
Thanks, I am now gonna test out your script in the project…
will report back as soon as something happens 
Thanks again
Mike
No worries, fixed the error, but no particles are showing during the collision.
why is this?
i just try the script and it worked , just follow that step by step it should work, if not, u need to tell me in details what u did what happend that i can help u.
did the present disapear after collision ?!
it disappeared, but it got really laggy ( FPS dropped from around 34 down to 3) and no particles appeared 
I need this to work now, so I can put it behind me and continue with the level design
Your original method of destroying the original object and spawning a new one should work fine. In any case, if whatever you have now still isn’t working, perhaps you could post your code in its current form.
something is wrong on ur project, because hide unhide or delete&create has the same result …
does ur particle working fine when u check-on the Renderer ?! i mean try to check it ON in the scene and see wat happen , if it’s working fine , its impossible that it will bug when disable enable it from a script !