I’m trying to create an impact effect, For instance when a character gets smacked I want a small yellow star shaped flash of light to appear next to the player. What would be the simplest and quickest way be to implement this using a texture?
I was thinking of creating an instance for the brief moment of impact but that seems like a waste.
Well, why not? It's not like the performance overhead is exactly huge. If you didn't want to, you could have a particle emitter attached to the player's head all the time, but set it's emmision to zero. Whenever you want to emit particles, just use particleEmitter.Emit(some number) to manually shoot out a bunch of particles without having to manage an entire lifecycle.
^ This. Why instantiate/destroy at all when all you have to do is either enable/disable or use the 'emit' property? (PS: I'd personally attach the emitter to the hand and not the head, but that's up to personal preference and circumstances)
Particles are definitely designed to do this. :) Use the Emitters Emit property and maybe its One Shot property in conjunction with the Animator's AutoDestruct property. (Set all those to true). Then set the emitters Min and Max energy to 1 each, so that at any one time, there can only be 1 particle.
Then, when you instantiate this system, it should spawn one particle, which you could then give a material that has the desired texture. When that particle is killed, the system Destroys itself, so essentially, it becomes a "fire and forget" system.
This is also the approach recommended by Unity for creating an explosion when an oildrum is fired on, see http://unity3d.com/support/documentation/Manual/Particle%20Systems.html under "Destroying GameObjects attached to Particles".
Particles?
– asafsitnerI thought about using particles, but I would have to attach them to an object and then instantiate them, then just delete them a half a second later.
– TheEmeralDreamerWhich btw I'm not opposed to doing that..I just thought there might be a more efficient way.
– TheEmeralDreamerWell, why not? It's not like the performance overhead is exactly huge. If you didn't want to, you could have a particle emitter attached to the player's head all the time, but set it's emmision to zero. Whenever you want to emit particles, just use particleEmitter.Emit(some number) to manually shoot out a bunch of particles without having to manage an entire lifecycle.
– syclamoth^ This. Why instantiate/destroy at all when all you have to do is either enable/disable or use the 'emit' property? (PS: I'd personally attach the emitter to the hand and not the head, but that's up to personal preference and circumstances)
– asafsitner