|
What I'm trying to do is trigger the prefab FireWorks from the particles folder when a rigidbody enters a trigger area, which is a box with "is Trigger". I am new to scripting, I've always been the modeler/animator. I'm not looking for specific code,I am looking for the logical flow of this example. I know I'll need a script that is attached to the trigger area. I know I'll need to somehow call on the particleEmitter component of FireWorks in that script to turn it on when the area is triggered. What I don't understand is how this all fits together. I understand that I'll first start with a class I'm guessing that in that class I'll need a variable to save the info from the FireWorks particle emitter state. But I'm not sure how that works or if that's how it is done. I know I'll need the functionality for the actual trigger But after that I am lost. I've really tried finding this on my own but most questions answered here basically assume you understand how things work together, I believe.
(comments are locked)
|
|
Detailed sequence:
public class TriggerGoal : MonoBehaviour;{
public ParticleEmitter fireWork; // this will appear as Fire Work in the Inspector
void OnTriggerEnter(Collider other){
fireWork.Emit();
}
}
NOTE: The Fireworks effect will explode whenever any rigidbody or CharacterController enters the trigger. If you want to fire the effect only when certain objects enter the trigger, you may compare other.tag to some specific tag: Remeber to tag the objects accordingly, if you want to use this alternative. I'm getting an error saying "No overload for method 'Emit' takes '0' arguments" when I build out the script.
May 20 '12 at 12:02 AM
obliviousart
The usually simpler way for point 3 is to grab the fireworks gameobject in the hierarchy panel and drop it on the fireworks variable of the trigger script in the inspector.
May 20 '12 at 12:03 AM
Bunny83
I've tried dragging and dropping but no go. I noticed if I put a number in, as in fireWork.emit(1);, the error goes away but the script still doesn't work.
May 20 '12 at 12:45 AM
obliviousart
It seems you're not familiar with the very basics of Unity, so i suggest you read the documentation carefully.
May 20 '12 at 01:09 AM
Bunny83
This error occurs when you define the variable fireWork as ParticleSystem - define it as ParticleEmitter instead, like in my answer. ParticleSystem is the new Shuriken particle generator, while ParticleEmitter is the old style particle generator, which is used in the Fireworks prefab (at least in the Particles Unity package)
May 20 '12 at 01:21 AM
aldonaletto
(comments are locked)
|
|
To emit particle, you will need a reference of the particle system component. The easiest to do that is to declare the variable as public and of type ParticleSystem (ParticleEmitter if it's not the new particle system). It's going to look like that : Then, you need to detect th collision. When the physic engine detect a collision, it sends a message to the game object being collided. If its collider is a trigger, that message is OnTriggerEnter. By implementing that function, you can receive the message. Now you need to make the emitter emit. For the new system, it would be fireWork.Play(); For the old one, fireWork.emit = true or fireWork.Emit(); Ok, so I need to already have the fireworks placed where I want it with its emitter disabled, and named fireWorks, correct? Or am I misunderstanding the concept of the referencing of the ParticleSystem? Edit: never mind, I see that doesn't work haha
May 19 '12 at 07:29 PM
obliviousart
(comments are locked)
|

Can you help with calling the FireWorks particleEmitter enable/disable? After more research that's pretty much the only thing I'm having trouble with now.