Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by obliviousart · May 19, 2012 at 05:03 PM · ontriggerenterlogic

Question about logical flow of a script

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

 public class TriggerGoal : Monobehaviour

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

 void OnTriggerEnter(Collider other)

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.

Comment
Add comment · Show 1
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image obliviousart · May 19, 2012 at 06:11 PM 0
Share

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.

2 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by aldonaletto · May 19, 2012 at 11:32 PM

Detailed sequence:
1- Drag the Fireworks effect to the scene and position it where you want; uncheck its field Emit in the Inspector, or the fire work will keep exploding forever;
2- Attach the script below to the trigger object;
3- Select the trigger object, then in the Inspector click the field Fire Work in the component Trigger Goal: this allows selection of the Fireworks effect you've placed in scene;
Presto! It's ready to play!

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:

   void OnTriggerEnter(Collider other){ 
     if (other.tag == "SomeTag"){ // only SomeTag tagged objects will work
       fireWork.Emit();
     }
   }

Remeber to tag the objects accordingly, if you want to use this alternative.

Comment
Add comment · Show 5 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image obliviousart · May 20, 2012 at 12:02 AM 0
Share

I'm getting an error saying "No overload for method 'Emit' takes '0' arguments" when I build out the script.

avatar image Bunny83 · May 20, 2012 at 12:03 AM 0
Share

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.

avatar image obliviousart · May 20, 2012 at 12:45 AM 0
Share

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.

avatar image Bunny83 · May 20, 2012 at 01:09 AM 0
Share

It seems you're not familiar with the very basics of Unity, so i suggest you read the documentation carefully.

avatar image aldonaletto · May 20, 2012 at 01:21 AM 0
Share

This error occurs when you define the variable fireWork as ParticleSystem - define it as ParticleEmitter ins$$anonymous$$d, 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)

avatar image
0

Answer by Berenger · May 19, 2012 at 07:04 PM

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 :

 // the first letter of fireWork being a lower case is just a convention.
 public ParticleSystem fireWork; 

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();

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image obliviousart · May 19, 2012 at 07:29 PM 0
Share

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 $$anonymous$$d, I see that doesn't work haha

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

7 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

C# - Problem with trigger that won't activate 1 Answer

OnTriggerEnter questions 2 Answers

Door Sound Script Help 1 Answer

OnTriggerEnter Glitch 1 Answer

Where to attach a script? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges