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 trinitysj96 · Jan 13, 2013 at 11:50 PM · triggersspawning-enemiesai problems

Respawn prefab after you destroy it

is it possible to respawn a prefab once it is destroyed.

ie.

Player hits trigger spawns enemy. then you kill the enemy and it destroys prefab. then if you hit the trigger again it respawns the same enemy to kill again. I just cant figure this out.

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 Lovrenc · Jan 13, 2013 at 11:51 PM

You should NEVER DESTROY THE PREFAB.

Destroy instance of a prefab.

Comment
Add comment · Show 15 · 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 trinitysj96 · Jan 14, 2013 at 12:02 AM 0
Share

how do you do that destroy the instance of the prefab?

ie.

 Instantiate(spawnobject, spawnspot[spawnedEnemies].transform.position, Quaternion.identity);

but how do you destroy the Instantiated object?

avatar image Lovrenc · Jan 14, 2013 at 12:04 AM 0
Share

Show me your Destroy code.

avatar image trinitysj96 · Jan 14, 2013 at 12:09 AM 0
Share

function Update(){

 SetPlayerName = Enemy.name;
 Text$$anonymous$$eshName.gameObject.GetComponent(Text$$anonymous$$esh).text = SetPlayerName + "\n\r" + hp;
     
 if (Input.Get$$anonymous$$eyDown("1")) {
     if (wasClicked) {
         wasClicked=true;
         audio.PlayOneShot(SmiteSound);
         
         //instantiate the projectile
         var instantiatedProjectile : Rigidbody = Instantiate (projectile, transform.position, transform.rotation); 
         
         //move the projectile 
         instantiatedProjectile.velocity = (enemies_list[ai$$anonymous$$g_at].GetComponent(Transform).position - transform.position)*speed;
         
         Physics.IgnoreCollision(instantiatedProjectile.collider, transform.root.collider); 
         
         // Send a damage message to the hit object          
         DamageNumber = Random.Range(1,(HitPoints/6));
         print ("hit : " + ai$$anonymous$$g_at + " with " + DamageNumber + " damage");
         hp = hp -= DamageNumber;
         Destroy(instantiatedProjectile.gameObject, ScorePoints); 
         
         //print ("ai$$anonymous$$g at : "+ai$$anonymous$$g_at);
         }
    }
 
 if(ai$$anonymous$$g == true)
 {    
 
 look_at = Quaternion.LookRotation(enemies_list[ai$$anonymous$$g_at].GetComponent(Transform).position - transform.position);
 look_at.x = 0;
 look_at.z = 0;
 transform.rotation = Quaternion.Lerp(transform.rotation, look_at, track_speed);
 
 if (Input.Get$$anonymous$$eyDown("-"))
     {
     if (ai$$anonymous$$g_at < enemies_list.length)
         ai$$anonymous$$g_at++;
         
     else
         ai$$anonymous$$g_at = 0;
     }
 
 if (Input.Get$$anonymous$$eyDown("="))
     {
     if (ai$$anonymous$$g_at > 0)
         ai$$anonymous$$g_at--;
 
     else                                                 
         ai$$anonymous$$g_at = enemies_list.length -1;
     }
 }
  
 if (hp <= 0)
 Destroy(gameObject);
 
 if (hp <= 0)
 {
     print ("scores: " + PlayerPrefs.GetString("playerName") + "--" + ScorePoints);
     //Instantiate(Explode, transform.position, transform.rotation);
     
     postScore(PlayerPrefs.GetString("playerName"),ScorePoints);    
 }

}

that is the update function with the destroy in it.

teh specific line is :

if (hp <= 0) Destroy(gameObject);

i would gusee it is there that i destroy the instantiated on not the actual game object itself? correct?

avatar image trinitysj96 · Jan 14, 2013 at 12:09 AM 0
Share

sorry it put it in three boxes.. dont know why it did that but it is all in one block...

avatar image Lovrenc · Jan 14, 2013 at 12:13 AM 0
Share

Because 4 spaces mean it should format text as code on this forum.

You're good, you arent destroying prefabs. Where is this script attached to?

Show more comments

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Did triggers inside loaded gameobjects break in a recent update? 0 Answers

Is there any way to see exactly which triggers are overlapping? 1 Answer

How to enable passing through collider if speed is high enough at collision point 0 Answers

On Trigger Enter just triggers once for same object 1 Answer

Problem: One Trigger activating a seperate Trigger it is not in contact with. 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