|
I have a global inspector variable and I can declare it either this way: or this way I then also have an explosion effect made with SHURIKEN tied to my script via the inspector. When I call on this explosion I instantiate it like this (in the place of my object), to make sure that explosion is there in the inspector How do I remove the effect after it has done its job ? I tried: and I got:
Does anyone have an idea ?
(comments are locked)
|
You need to store what you instantiated in a temporary variable so that you can talk to it afterwards. +1. You may not use Destroy(explosion) as the explosion variable points to the actual asset and not an instance of that asset. Store the instance on creation and destroy that later.
Mar 21 '12 at 03:06 PM
by0log1c
Thanks, that did it! Kudos and a cookie to You Sir!
Mar 21 '12 at 03:09 PM
Sarnum
Using GameObject didn't work to me to destroy the explosion. If I cast the Instantiate with "as GameObject", the Destroy won't do anything. If I cast like you said, I get this error using C#: InvalidCastException: Cannot cast from source type to destination type. But Instantiating to a Transform, and Destroying the transform.gameObject worked just fine :) Thanks for this tip.
Sep 11 '12 at 12:27 AM
Almondega
(comments are locked)
|
|
I'm very sorry but I'm using Shuriken particle system and not the old legacy elipsoid particle emitter that had the autodestruct button. If I used the old one I wouldn't have that problem but I do not want to use an outdated system while learning unity 3.5. No worries.
Mar 21 '12 at 07:35 PM
fafase
(comments are locked)
|
|
if(explosion) { var newexplosion : GameObject = Instantiate(explosion,transform.position,transform.rotation); Destroy(newexplosion,3); }
(comments are locked)
|
|
1.unchecked looping from particle system editor 2.create a transform variable in your script as public(example explosionTrans)and set your particle object from editor. 3.now in your update method explosionTrans.particleSystem.transform.position=this.transform.position; explosionTrans.particleSystem.Play();
(comments are locked)
|
