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 Deatructo · Dec 20, 2013 at 10:25 PM · spawnstop

Spawn object problem

Hey how is the unity community doing today ive made an exploding car that replaces itself with a burnt on fire debris pile but when i blow the car up it spawns 7 times..... this is because of the explosion effect how would i got about making this only happen once or stopping it with out stopping my effect if it spawn into the blowing up car so i need them to stay together so i can throw the debris this is what i need to only run once

 void Die (){

     if (deadReplacement) {
         Transform dead = Instantiate(deadReplacement, transform.position, transform.rotation) as Transform;
 
         // Copy position & rotation from the old hierarchy into the dead replacement
         CopyTransformsRecurse(transform, dead);

         }
         
     }    
 }    
 static void CopyTransformsRecurse ( Transform src , Transform dst ){
     dst.position = src.position;
     dst.rotation = src.rotation;
     
     foreach(Transform child in dst) {
         // Match the transform with the same name
         Transform curSrc = src.Find(child.name);
         if (curSrc)
             CopyTransformsRecurse(curSrc, child);



UPDATE :

I figured out it was spawning as many times as my bullets hit it before it dies so when i shoot a shotgun at it it makes copys of how many bullets hit it when health hi zero still have the problem anyone have any ideas? on how to make it spawn once instantly and only once after explosion

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 Benproductions1 · Dec 21, 2013 at 01:27 AM

Hello,

Usually problems like these are caused because the specific event is fired multiple times per frame (or before the effect executes), causing multiple effects simultaneously. With the event being the death of your car and the effect being the instantiation of the deadReplacement.

The usual way around the issue is to keep track of the objects state. The state is changed when the event is fired and is checked before the effect executes. In your case you would keep track of whether your car "is dead":

 private bool isDead = false;
 
 public void Kill() {
     if (!isDead) {
         isDead = true;
         Die();
     }
 }

Hope this helps,
Benproductions1

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 Deatructo · Dec 21, 2013 at 04:39 PM 0
Share

ok just got this im rebooting my pc then ill try this ill let you know thanks

avatar image Deatructo · Dec 21, 2013 at 06:09 PM 0
Share

ok im having trouble with it im using this do get die to run

 if (hitPoints <= 0.0f){
             Send$$anonymous$$essage("Die");


i cant get it to run at all with the script you made it doesent play the effect either it cuts it short is there a way to make it toggle it on and then toggle right back off?

avatar image Deatructo · Dec 21, 2013 at 08:19 PM 0
Share

got just made it on a different layer and spawned it before the explosion

avatar image Benproductions1 · Dec 21, 2013 at 11:50 PM 0
Share

The code I wrote was a basic example of how it would be integrated into your code. It is not a separate script, nor have I tested it with any working example. It's just pseudocode (thats syntactically correct) and lends to explain the solution :)

Also, you should avoid using Send$$anonymous$$essage

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

19 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

Related Questions

Timer that stops at the end of the game 3 Answers

Help: script that worked don't work with Unity 3.5 0 Answers

C# Make array based on script variable 1 Answer

Spawned units disappear 2 Answers

Scripts stop working in Maximize On View and testing on Android 0 Answers


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