• 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 /
  • Help Room /
avatar image
0
Question by Undyinglag · Feb 22, 2016 at 05:46 PM · c#2d gameparticlesbulletexplosion

how to activate a particle when bullet hits a collider?

so, im trying to make a explosion particle appear once when the bullet hits any collider. i used instantiate to make the explosion particle appear when its called but the particles do not appear, instead the instance of it is just created without the particles being animated.

tried to put (ParticleSystem.enableEmission = True) somewhere but the code would always come up with some syntax error or something... im still a beginner in programming. So how can i put that in the code? or, is there a better way to achieve the result i want? thanks in advance!

my script used on the bullet prefab:

 public class blueLaserScript : MonoBehaviour
 {
     public ParticleSystem explosionParticle;
     public int dmg = 1;
     public float lifeTime = 3f;
     public float maxLifeTime = 0.35f;
 
     void Start()
     {
         lifeTime = maxLifeTime;
     }
 
     void FixedUpdate()
     {
         if (lifeTime > 0)
         {
             lifeTime -= Time.deltaTime;
         }
         else
         {
             Destroy(gameObject);
         }
     }
 
     void OnTriggerEnter2D(Collider2D col)
     {
         if (col.isTrigger == !true && !col.CompareTag("Enemy"))
         {
             Instantiate(explosionParticle, transform.position, transform.rotation);
             Destroy(gameObject);
         }
 
         if (col.isTrigger == !true && col.CompareTag("Enemy"))
         {
             col.SendMessageUpwards("Damage", dmg);
             Instantiate(explosionParticle, transform.position, transform.rotation);
             Destroy(gameObject);
         }
     }
 }
Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by UCSIM · Feb 22, 2016 at 10:58 PM

If I am understanding correctly you are trying to get the particle system to start emitting. The method I use for this is calling Play() on a particle system object. Then you can set .enable to false when you're done with it.

Hopefully I answered your question.

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 Undyinglag · Feb 23, 2016 at 07:01 PM 0
Share

thanks it helped! took me a while to figure on how to put it though. made a separate script for the particle:

 public float lifeTime = 0.5f;
     public float maxLifeTime = 0.26f;
     private ParticleSystem thisExplosion;
 
     void Start ()
     {
         lifeTime = maxLifeTime;
         thisExplosion = gameObject.GetComponent<ParticleSystem>();
     }
 
     void Update()
     {
         thisExplosion.Play();
 
         if (lifeTime > 0)
         {
             lifeTime -= Time.deltaTime;
         }
         else
         {
             Destroy(gameObject);
         }
     }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

115 People are following this question.

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

Related Questions

How to create a link between particle and script C# 1 Answer

How to move a bullettrail the direction the player is facing 0 Answers

Constant fire at target 2 Answers

Score increasing/decresing too much 1 Answer

How to shoot bullets depending on the players position???,shooting bullets depending on players x position 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