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 Jammer3000 · Feb 27, 2013 at 07:26 PM · collisionsystemparticle

How to create particle system on a collision?

Hi I need to know how to emit a particle system on collision. For example I have a sphere and my character has a player, I have it so when the player hits the sphere it gets destroyed and a particle system emits. But it won't work the code i'm using is below. Thanks for your help(:

var explosionPrefab : Transform;

function OnCollisionEnter(collision : Collision) { if (collision.gameObject.tag == "Hammer") { Debug.Log("Die ball!"); Instantiate(explosionPrefab); 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
5
Best Answer

Answer by Kiloblargh · Feb 27, 2013 at 07:36 PM

You weren't using Instantiate the right way.

 var explosionPrefab : Transform;
     
 function OnCollisionEnter (collision : Collision) { 
     if (collision.gameObject.tag == "Hammer") { 
         Debug.Log("Die ball!"); 
         var boom : GameObject = Instantiate(explosionPrefab, transform.position, Quaternion.identity);
         Destroy(gameObject, 0.1); // also sometimes destroying right away causes problems
     }
 }
Comment
Add comment · Show 2 · 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 AlucardJay · Feb 27, 2013 at 07:44 PM 0
Share

Upvoted. I swear I just answered this same question : http://answers.unity3d.com/questions/407498/missingreferenceexception-the-object-of-type-trans-1.html

avatar image fafase · Feb 28, 2013 at 07:00 AM 1
Share

What kind of problem do you get while destroying right away? Because Update is already delayed to the end of the frame, so you are just delaying a little more with the risk that the collision could be detected again and creating a profusion of explosion since in 0.1s you can get up to 6 or 7 frames.

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

11 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

Related Questions

How to emit two partcle systems in one particle emmiter 1 Answer

How to load a scene on collision 2 Answers

Script to scale particle system 2 Answers

How to play an audio one shot clip on a collision 1 Answer

Particle System, change the velocity by script 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