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 safak93 · Mar 22, 2014 at 05:05 PM · prefabspawnparticle

Play after collision a Particle-prefab and spawn a new Coin-Prefab

Hey guys.

I have now created a particle effect and ad it to a prefab. When I start the game the particle effect plays immediately without any collision. What I'm doing wrong here? EDIT: I have solved the first problem.

If the collider is destroyed, how I can spawn a new coin-prefab on the same position?

As last, how can I destroy a collider separately? Currently if I'm jumping between the 2 colliders both will destroyed. I would like it that only once per jump destroyed a collider.

I hope you can help me.

Here is the script(on the line 20 for particle effect):

 using UnityEngine;
 using System.Collections;
 
 public class BlockBreakable : MonoBehaviour {
 
     public float breakableTime = 0.5f;                        
     AudioClip soundBumpBreak;                                
     public string tag = "Player";
     public PlayerControllerScript controller;
     public Transform particleprefab;
     public GameObject coinprefab;
 
     
     void OnCollisionEnter2D(Collision2D coll)
     {
         if(coll.gameObject.tag == tag && !controller.grounded)
         {
             BreakableWait ();
             Destroy (this.gameObject, breakableTime);        
             Instantiate(particleprefab, new Vector3(0, 0, 0), Quaternion.identity);
         }
     }
     
     IEnumerator BreakableWait ()                            
     {
         yield return new WaitForSeconds(breakableTime);        
     }
     void Start ()                                            
     {
         audio.clip = soundBumpBreak;                        
         audio.Play ();                                        
     }
 }
Comment
Add comment · Show 2
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 getyour411 · Mar 22, 2014 at 05:06 PM 0
Share
  1. uncheck play on Awake

avatar image safak93 · Mar 22, 2014 at 05:45 PM 0
Share

I don't mean the sound effect.

1 Reply

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

Answer by SkaredCreations · Mar 22, 2014 at 07:21 PM

Use transform.position:

 void OnCollisionEnter2D(Collision2D coll)
     {
        if(coll.gameObject.tag == tag && !controller.grounded)
        {
          BreakableWait ();
          Instantiate(particleprefab, transform.position, Quaternion.identity);
          Instantiate(coinprefab, transform.position, Quaternion.identity);
          Destroy (gameObject, breakableTime);       
        }
     }
Comment
Add comment · Show 3 · 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 safak93 · Mar 22, 2014 at 07:24 PM 0
Share

Thanks, that works too.

avatar image SkaredCreations · Mar 22, 2014 at 10:09 PM 0
Share

However just to be clear, your BreakableWait function does nothing and also it isn't currently executed as coroutine because you're not calling it through StartCoroutine. You can just delete the line where you call it.

avatar image safak93 · Mar 22, 2014 at 10:11 PM 0
Share

I know, I have already done it.

How can I destroy a collider separately? Currently if I'm jumping between the 2 colliders both will destroyed. I would like it that only once per jump destroyed a collider.

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

spawning a prefab that have animation 1 Answer

Prefab spawning without running script (uses VR controllers) 1 Answer

Instantiate Prefab 0 Answers

Pretty simple problem: Bullet hole spawn wrong 1 Answer

How can I spawn a prefab relative to a cube position? 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