Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 mediamavrick · Mar 06, 2014 at 01:41 PM · prefabparticlesystem

How do I use my particle prefab on collision with my brick?

Im new to programming so this is most likely a noob question but I was wondering how I would make my particle prefab run once it collides with a brick. I have found other sources online of how to do this but none of them seem to work for me. Does anyone know how I would do this?

 private var score : int=0;
 var guiScore : GUIText;
 
  var blue : Texture;
 
  var isBlue : boolean = false; 
  
  var brickPieces : GameObject;
  
 function Start () {
 guiScore.text="Score: 0";
 }

 function OnCollisionEnter(col : Collision){
 
 if(col.collider.name == "Brick3"){
 Destroy(col.gameObject);
 
 //I want the brick to explode showing my particles here
 
 brickPieces(col.gameObject);
 score += 10;
 guiScore.text= "Score: " + score;
 renderer.material.mainTexture = blue;
 isBlue = true;
 
 }
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 nesis · Mar 06, 2014 at 01:57 PM

Is the GameObject variable called brickPieces your particle system? It's hard to tell for sure.

If that's the case, you can make accessing the particle system a little easier by changing that variable from being GameObject to being ParticleSystem. Then, when it comes time to start showing particles, you can use this:

 brickParticles.Play();

This method will just need you to have the particle system's "Play On Awake" checkbox to be unticked in the Inspector, so it doesn't start playing the moment the scene starts / its GameObject activates.

Comment
Add comment · Show 4 · 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 mediamavrick · Mar 06, 2014 at 02:28 PM 0
Share

I did everything you said and even that wont work.

  1. set brickPieces to ParticleSystem

  2. insert brickPieces.Play(); where I want it to deploy in the script

  3. $$anonymous$$ade sure the particle systems Play On Awake checkbox was unchecked.

None of this seemed to work. I really thought it would to because it all made sense. Do you have any other suggestions to help me get this thing to work?

avatar image mediamavrick · Mar 06, 2014 at 02:34 PM 0
Share

Even If I just put brickPieces.Play(); in the update method, it never once runs in the game. This is a serious problem. I have it as a Prefab but its not in the game object bar with all of my other objects. I have it like this because I only want it to run at certain instances.

avatar image nesis · Mar 06, 2014 at 02:44 PM 0
Share

Oh, so you don't have an instance of it? Use Instantiate(brickPieces,transform.position,transform.rotation) then. That'll take your prefab (which tells Unity what you want to create) and make an instance of it (which actually puts it in your game).

avatar image mediamavrick · Mar 06, 2014 at 02:57 PM 0
Share

THAN$$anonymous$$ YOU! that totally worked. $$anonymous$$uch appreciated kind sir.

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

21 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

Related Questions

Particle system that follows player and turns on or off 1 Answer

Adding prefab ParticleSystem to a GameObject? 0 Answers

Particle Sytem with Prefabs 0 Answers

Particle System Attached to Prefab 1 Answer

How to add a prefab containing Animation to a GameObject? 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