Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 michvaw90 · Apr 19 at 02:14 AM · particle systeminstantiating

How should I call my particle system (a small explosion) when my projectile hits enemy?,particle system not instantiating OnCollisionEnter

Hi, I have a particle system that I want to instantiate or play? I'm not sure which one maybe someone can advise. I want my particle system to show when my projectile bullet hits my enemy. My enemy is disabled back to the pool it came from in my EnemyShot() coroutine when my projectile hits the collider of my enemy. That is working, my enemy becomes disabled. But my particle system is not happening.

I have the instantate call for my explosion particel system in both my OnCollisionEnter function and my EnemyShot() function but neither seem to do anything at all... What's wrong?

btw this is my enemy script attached to my enemy prefab

public ParticleSystem explosion; public Transform explosionLocation;

 private void OnCollisionEnter(Collision collision)
 {
     if (collision.gameObject.CompareTag("Projectile"))
        UpdateEnemyCountdown();
     Instantiate(explosion, explosionLocation);
     StartCoroutine(EnemyShot());
         
 }

 public IEnumerator EnemyShot()
 {
     Instantiate(explosion, explosionLocation);
    
     ObjectPooler.Instance.DeactiveEnemy(gameObject);
     yield return null;
 }

}

,I have a bullet projectile and upon collision with an enemy I want it to call my particle system which is a little explosion.

The enemy is enabled from a pool then deactivated upon hit by the projectile (in a couroutine)

My attempt to call my particle system is not doing anything.

public ParticleSystem explosion; public Transform explosionLocation; ... ... ... private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Projectile")) UpdateEnemyCountdown(); Instantiate(explosion, explosionLocation); StartCoroutine(EnemyShot()); } .....

public IEnumerator EnemyShot() {

     Instantiate(explosion, explosionLocation);
    
     ObjectPooler.Instance.DeactiveEnemy(gameObject);
     yield return null;
 }

Any suggestions on how to get my particle explosion going? btw private void OnCollisionEnter(Collision collision) { if (collision.gameObject.CompareTag("Projectile")) UpdateEnemyCountdown(); Instantiate(explosion, explosionLocation); StartCoroutine(EnemyShot()); }I have this enemy script on my enemy prefab (that is pooled, disabled upon EnemyShot()

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 HalilAlper · Apr 19 at 07:05 AM

  1. Using OnCollisionEnter for triggering solutions would cause you wacky problems. You should try OnTriggerEnter instead, and form your stuff accordingly. I think this might work for you.

  2. Instantiating for this stuff is bad practice. I would create an object pool inside my player and move the position and rotation accordingly.

  3. Also make sure your particles' Looping is false so whenever you play(), it will play the explosion particle only once and I'm pretty sure that's what you want.

Comment
Add comment · 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

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

181 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 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

Particle System doesn t simulate in animation in editor 0 Answers

Gameobjects instantiating in the wrong position 0 Answers

Idiot can't play a particle system onCollisionEnter 2 Answers

Create particle onTriggerEnter for simulating a hit 0 Answers

How to make particles makes player feels about SPEED inside spaceship 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