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 Ledifen · Aug 03, 2017 at 10:47 AM · c#unity 5scripting problembeginnerparticle system

[Newbie] Particle System not playing, C# (unity 5.5)

Hello everyone :)

RECAP VERSION : I want a game object to play a particle system once and disappear when it touches another GameObject with the tag "cube".

DETAILED VERSION : I have a canon with which you knock cubes of platforms. The cannonball should work like a bomb in that, when it touches a gameObject with the tag "cube", it plays a particle system (like an explosion effect) then disappears. I don't need the "explosion" to have any kind of physical force, it is just there to make the disappearing look pretty.

Everything works well except the particle system. I've looked on the Internet, of course, but I can't get it to work. I honestly can't tell you everything that I've tried. I did try with OnTriggerEnter, with different lines of code, with a getComponent, I've moved the lines a lot, created functions and calling them, removing and adding things... Everything that seemed logical and possible with my very limited understanding of Unity and scripting. I didn't get that much of compile errors. It just doesn't play. Here is the script I have now (no compile error but still doesn't work):

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BallBehaviour : MonoBehaviour {
 
     public ParticleSystem ps;
 
     void OnCollisionEnter (Collision ColBallCube){
 
         if (ColBallCube.gameObject.tag == "cube") {
             //Destroy (gameObject, 0.5f);
             ParticleSystem.EmissionModule em = ps.emission;
             em.enabled = true;
         }
     }
 }

(just to be sure, I've toggled the destroy part to commentary line).

Obviously I'm doing something wrong or missing something. It is also possible that there's a problem with the particle system settings (looping ? Play on Awake ? etc.).

Does someone has an idea of how to solve this? Thanks for any kind of help.

Have a good day :)

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

3 Replies

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

Answer by Ledifen · Aug 09, 2017 at 07:35 PM

After a lot of failed attempts, I finally managed to make it work properly. With the advice of @Y00, this is what I have (and it works) :

  • 1 empty object (emptyHoldingPs) with the particle system;

  • 1 game object sphere (physcisBall) that is visually the "cannon ball", but has no physical existence except the look (basically just a mesh);

  • 1 empty object (cannonBall) with a rigidbody, the sphere collider and the script.

The first two are attached as child of the third, so the empty object "CannonBall" is what I throw with my canon.

 public GameObject emptyHoldingPs;    //drag the empty Obj with the particle system component
 public GameObject physicsBall;       //drag the game obj with the mesh
 private bool hasCollided = false;
 
 ParticleSystem ballParticleSystem;
 
 
 void Start(){
     
     ballParticleSystem = emptyHoldingPs.GetComponent<ParticleSystem> ();
     ParticleSystem.EmissionModule em = ballParticleSystem.emission;
     em.enabled = false;    
 }
 
 void OnCollisionEnter (Collision ColBall){
     
     if (hasCollided == false){
         ParticleSystem.EmissionModule em = ballParticleSystem.emission;
         em.enabled = true; 
         ballParticleSystem.Play();
         hasCollided = true;
         Destroy (physicsBall, 0f);     //  I destroy the mesh right away
         Destroy (gameObject, 0.5f);   // I destroy the entire cannon ball with a delay so the particle system has the time to play completely once.
     
 
     } else {
         
         hasCollided = false;
     }
 }

To deal with a potential collision happening between the first collision and the "Destroy (gameObject, 0.5f);", I'v used a boolean "hasCollided". The part with the boolean is untested, but the rest works.

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
1

Answer by Y00 · Aug 03, 2017 at 01:06 PM

public ParticleSystem MyParticle; //Specify the link in the inspector

if (ColBallCube.gameObject.tag == "cube") MyParticle.Play();

.......

MyParticle.Stop();


or place your ParticleSystem on any GameObject and: gObj.SetActive(true); gObj.SetActive(false);

Comment
Add comment · Show 10 · 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 Ledifen · Aug 03, 2017 at 01:37 PM 0
Share

Okay thanks for the answer :)

If I choose the first solution, where do I put "$$anonymous$$yParticle.Stop();". In your lines of code, what does the line of dot represent? I've already tried something with Play and Stop, but I don't know how to handle the rest of the code concerning ParticleSystem.

For now, that's what I have (didn't put the Stop since I'm not sure where to put it):

 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BallBehaviour : $$anonymous$$onoBehaviour {
 
     public ParticleSystem ps;
 
     void OnCollisionEnter (Collision ColBallCube){
 
         if (ColBallCube.gameObject.tag == "cube") {
             //Destroy (gameObject, 0.5f);
             ps.Play();
             ParticleSystem.Emission$$anonymous$$odule em = ps.emission;
             em.enabled = true;
             //ps.Stop ();
         }
     }
 }

I'm sure I'm missing something here, and I'm pretty sure it's simple, but for now it doesn't click in my $$anonymous$$d... Sorry :/

avatar image Y00 · Aug 03, 2017 at 02:11 PM 0
Share
 using System.Collections;
 using System.Collections.Generic;
 using UnityEngine;
 
 public class BallBehaviour : $$anonymous$$onoBehaviour {
 
   public ParticleSystem ps;
  
   void OnCollisionEnter (Collision ColBallCube){
  
       if (ColBallCube.gameObject.tag == "cube") {             
           ps.Play();
           StartCoroutine(Cor());
       }
   }
 
 IEnumerator Cor() 
 { 
 yield return new WaitForSeconds(1); 
 ps.Stop(); 
 Destroy (gameObject);
 }
 
 }


or simple: if (ColBallCube.gameObject.tag == "cube") {
ps.Play(); Destroy (gameObject, 1f); }

avatar image Ledifen Y00 · Aug 04, 2017 at 09:39 AM 0
Share

@Y00

Again, thank you for the time you spend on this question. :)

Unfortunately, it doesn't work (I've tried both solutions). There's no compile error, but it doesn't play (but the destroy works fine).

I don't know, maybe it has to do with the particle system in itself. I've used the default settings, then changed the "play on awake" and "looping" booleans. It just wouldn't play.

avatar image Y00 Ledifen · Aug 04, 2017 at 10:24 AM 0
Share

"looping" - true, "play on awake" - false ?

Is it displayed in the scene window?

Show more comments
avatar image Y00 Y00 · Aug 04, 2017 at 11:58 AM 0
Share

You can see the work with the particles in my project. https://yadi.sk/d/5lsDUfkA3LiCBJ

for example Game->Grid->AirPlane->AirPlaneForRotate->ParticleWater looks like your situation. However, this particle is displayed not by collision, but by pressing the interface button (Similar code in the file Assets\Scripts\Airplane.cs method IWatering())

I do not speak English)) (use Google translator)

avatar image Ledifen Y00 · Aug 04, 2017 at 12:36 PM 0
Share

Thanks a lot for all the help you've provided me.

I see that your scripts are very complete and maybe a tad bit too complex for me to understand. For example, I don't know what "Abilities", "WateringAbility", "IsUse" and "TimeUse" represent so I'm struggling with that.

Anyway, I'll try finding an other way of doing this. I'll stop bothering you.

Again, thank you for your time and help, it's very much appreciated. :)

avatar image
0

Answer by pcortesr · Oct 09, 2017 at 08:13 PM

Also you can create a gameObject with a particle system with play on wake and activate this when you can use the particle. @deleu

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

406 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 activate gameObjects based on a boolean from another scene? 1 Answer

Using AirBrakes on mobile device with Standard Assets AircraftController 0 Answers

Hello, could I get some help with my inv system? 1 Answer

Built project, now scripts are missing. 2 Answers

Rotating a cube horizontal axis 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