Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
  • 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.

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 move a bullettrail the direction the player is facing 0 Answers

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

Add a public Tranform target from another scene 0 Answers

NullReferenceException: Object reference not set to an instance of an object, again 2 Answers

How to make -Count down Timer on entrance and exit triggers and display remaining time 0 Answers


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