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 xXTURDLEXx · Jul 21, 2013 at 12:20 AM · airespawnenemies

How to Respawn Ai Enemies After Destroy Gameobject??

I have a bullet script that sends out a message to deduct health if what the Raycast hit was tagged with enemy. I also have a health script that when it recives the message, it takes away the var damage (25). In this script, when it reaches "0", the game object is destroyed. All works but when I add a respawn part.... well it kind of works.... I mean the Ai respawns and all but it no longer chases me. I also have the Ai as a prefab thinking that this would help.

(HealthScript) SCRIPT: #pragma strict

 var Enemy : GameObject;
 var Health = 10;
 
 function ApplyDammage (Dammage : int)
 {
     Health -= Dammage;
     
     if(Health <= 0)
     {
         Dead();
     }
 }
 
 function Dead()
 {
     Destroy (gameObject);
     Health = 10;
     Respawn();
 }
 
 function Respawn()
 {
     Instantiate (Enemy, Vector3(7,2.18094,0), Quaternion.identity);
     
 }
Comment
Add comment · Show 3
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 robertbu · Jul 21, 2013 at 04:44 AM 0
Share

Nothing in this script is helpful in figuring out what is going on. Likely the issue is in your Enemy script.

avatar image Dougbott · Jul 21, 2013 at 05:10 AM 1
Share

On your Prefab you have the AI script attached to the Enemy Prefab? I am assu$$anonymous$$g you do. When it respawns do you see the script on the newly instantiated enemy?

avatar image xXTURDLEXx · Jul 23, 2013 at 10:28 AM 0
Share

Ha I found the Problem! its not solved but I still found out whats going on. When I play the game, my Ai moves perfectly but once its dead it doesnt move. Seeing this, I investigated. I later found out that the script for health and Ai were unchecked, not when I start the game but when the Ai has died and respawned. Anyone know how to fix this???

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by pdunton · Jul 21, 2013 at 02:47 AM

Im not very good at coding, but this sounds like some problem i had. Try instead of destroying the object, scaling it really really really small, and coding it to stop the AI. And then upon respawn, scale it back up and restart the AI. Sorry if this is no help.

Comment
Add comment · 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
0

Answer by Dougbott · Jul 23, 2013 at 02:06 PM

To enable/disable scripts or any other "stuff" on your gameObject, just use this:

 //This is to check it
 gameObject.GetComponent<myAIScript>().enabled = true;
 
 //This is to uncheck it
 gameObject.GetComponent<myAIScript>().enabled = false;

Hope this helps! Good luck!

Comment
Add comment · Show 1 · 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 xXTURDLEXx · Jul 24, 2013 at 08:28 AM 0
Share

??U$$anonymous$$?? JavaScript???

avatar image
0

Answer by coAdjoint · Jul 23, 2013 at 02:16 PM

You need a game manager script, like that used in the AngryBots project that comes with Unity.

The GameManager class works by instantiating a number of enemies at the start of the game. When these enemies are 'killed' in the game, they are deactivated and reset.

You may also want to check out this video by Prime31

http://www.youtube.com/watch?v=IX041ZvgQKE

You'll also learn about LINQ at the same time!

Comment
Add comment · 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
0

Answer by Halleflux · Jul 24, 2013 at 09:22 AM

 gameObject.GetComponent(myAIScript).enabled = true;

Same as Dougbott's answer, only in JavaScript.

A good idea, if you are using the script more than once, it to put it in a variable:

 var scriptName : ScriptName;
 scriptName = gameObject.GetComponent(ScriptName); //As a side note: you can get other GameObject's components with this script. This is useful in many circumstances.

GetComponent documentation.

Comment
Add comment · Show 1 · 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 xXTURDLEXx · Jul 24, 2013 at 09:29 AM 0
Share

Thanks, will try soon. :)

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

2D top-down shooter AI 0 Answers

Different enemy types script design 1 Answer

AI Target Finding Optimization 0 Answers

How do I make my player re-spawn in its original place on collision of enemy? 1 Answer

How to add respawn to enemy AI? 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