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 /
avatar image
0
Question by karlo25 · Apr 25, 2017 at 12:09 AM · unity 5particlesystemparticle

Is there OnParticleCollisionExit()? If none how to make.

I made a weapon that throwing particles as bullet. If the particle(weapon) collide to the enemy obviously the enemy will decrease it health and a Hit_Enemy animation will play. My problem is I cant change the animation into Run_Enemy because I cant exit the particle collision.

Sample Code:

void OnParticleCollision() {

     //Debug.Log (currentHealth);
     enemy_animation.SetBool ("isHit", true);

     enemyCurrentHealth -= PlayerDamage;
     if (enemyCurrentHealth < 0)
         StartCoroutine (Died ());
     else
     UpdateHealthBar (); 


}//on particle collision

I want to change the animation if the particle exit to the enemy collider. I hope you can help me. Thank you.

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mr_Kaizoku · Aug 29, 2018 at 07:51 PM

I know it's pretty late, but if someone searching i want to help him.

Well as i search for it but didn't find any. So i came with my own, i don't know if its a great answer but it work well.

 public class ParticleBehaviour : MonoBehaviour {
         
 public static bool PARTICLE_COLLISION = false;
             
 private void LateUpdate() {
             PARTICLE_COLLISION = false;
 }
         
 private void OnParticleCollision(GameObject other) {
                         PARTICLE_COLLISION = true;
 }
 }

and now you can check it in a object script with which you want to make collision do this is update()

 private void Update() {
 if (!ParticleBehaviour.PARTICLE_COLLISION) {
 // now you can write your code for after collision ends
 }
 }


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
avatar image
0

Answer by MBrown42 · Feb 07, 2020 at 07:12 PM

My game had slightly different requirements than knowing when in theory a particle or stream "exited". For me, the situation is that a stream of repair particles hits something that needs repair, I needed to know when it stopped. In a nutshell, I overwrite a timestamp of the last time a particle hit. Then in fixed update, I checked if it's been longer than a threshold and if so, deem the particle collisions have stopped.

Hopefully this is useful to someone. Thanks! Matt

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BreakableRepairableThingPiece : BRTChild
 {
     // Have particles collided?
     public bool m_bParticlesCollided = false;
     
     // When did particles start colliding
     public float m_fRepairParticleStartCollisionTime;
     
     // How long do we go without particle collision before saying we are not?
     public float m_fRepairParticleNoCollideTime = 0.2f;
     
     // For future scalability, currently unused
     public int m_iLastLayerCollided;
 
     // we get hit with a particle
     void OnParticleCollision(GameObject _otherGO)
     {
         // We only track last particle collided info for layer 16 (repair particles)
         if (_otherGO.layer == 16 )
         {
             // Record / Overwrite the time we just got hit with a repair particle
             m_fRepairParticleStartCollisionTime = Time.time;
             
             // Set our particles colliding flag to true
             m_bParticlesCollided = true;
             
             // For future scalability, currently unused
             m_iLastLayerCollided = _otherGO.layer;
         }
         myBRT.registerParticleCollision(_otherGO);
 
     }
 
     // Every frame check if we have gone long enough without getting hit by repair particles
     // To deam ourself no longer under repair
     public void FixedUpdate()
     {
         // If it's been long enough
         if (m_bParticlesCollided && Time.time - m_fRepairParticleStartCollisionTime >= m_fRepairParticleNoCollideTime)
         {
             // Set our particles colliding flag to false
             m_bParticlesCollided = false;
             
             // Tell our parent that we are no longer getting repaired
             myBRT.RegisterParticleCollisionStop(m_iLastLayerCollided);
         }
     }
 }
 
 

,

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

ParticleSystem at Photon Not working! 2 Answers

Did the behavior of gravity of particleSystem ever changed? 0 Answers

[Tank Game Tutorial] Particles Only Appear While Turning 2 Answers

Teleporting old particle system 0 Answers

ParticleSystem.play in unity 5? 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