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 Isaac15 · Sep 07, 2014 at 06:38 PM · enemyrespawnkill

How kill an enemy and respawn after die

Hello, iI'm making a 3D game and I want when enemy's life reaches 0 this disappear and respanw in the same area where started when the game starts.

Here I put the script of life

Thank you

     1 var saludActual=100; var
       saludMaxima=100.00;
       
       var largoBarra=0.0;
     5 
       function Start () {
       largoBarra=Screen.width/10; }
       
       
    10 function Update () { AjustarSalud(0);
      
      
      }
       function OnGUI() { GUI.Box(new
   15  Rect(1150,30,largoBarra,20),saludActual+'/'+saludMaxima);
      
      }
      
      function AjustarSalud(salud) {
  20  saludActual+=salud;
      
      
      if(saludActual<0) {
      
  25  saludActual=0; }  
      if(saludActual>saludMaxima)  {
      
      saludActual=saludMaxima; }
      
  30  if(saludMaxima<1){ saludMaxima=1;
      
      }
      
      largoBarra=(Screen.width/10)*saludActual/saludMaxima;
  35  
      }
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Mimumu84 · Sep 07, 2014 at 07:03 PM

You could create another script attached to an empty GameObject that will help to count the number of enemies in the area. When the 'total number of enemies' is below the maximum number of enemies, you can instantiate your enemy from the GameObject or a specific spawnpoint.

In your enemy script, when your enemy health = 0, you can access the script attached to the empty GameObject using 'GetComponent("myscript")" and subtract the current number of enemies by 1. Then destroy your enemy transform. Add a bit of time between your subtraction with 'current number of enemies' and destoying your transform with "yield WaitForSeconds(float).

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 ComeSweetDeath · Sep 07, 2014 at 07:09 PM

 var saludActual=100; 
 var saludMaxima=100.00;
 var largoBarra=0.0;
 private var respawnPoint : Transform;
 
 function Start () {
     largoBarra = Screen.width/10; 
     respawnPoint = transform.position;
 }
 
 
 function Update () {
     AjustarSalud(0);
     Respawn ();
 }
 
 function OnGUI() { 
     GUI.Box(new Rect(1150,30,largoBarra,20),saludActual+'/'+saludMaxima);
 }
 
 function AjustarSalud(salud) {
     saludActual += salud;
 
     if(saludActual<0) {
         saludActual=0; 
     }  
     if(saludActual>saludMaxima)  {
         saludActual=saludMaxima; 
     }
     if(saludMaxima<1){
         saludMaxima=1;
     }
 
     largoBarra=(Screen.width/10) * (saludActual/saludMaxima);
 
 }
 
 function Respawn () {
     if (saludActual <= 0){
         transform.position = respawnPoint.position;
         saludActual = saludMaxima;
     }        
 }

A tiny modification based on your script. Basically it simply records the position when your character started. And when it's health reaches 0, it is teleported to the starting location with max health.

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

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Respawn Enemy Prefab after its destroyed 1 Answer

Kill enemy when animation is playing 1 Answer

[C#] Respawning system Enemies 0 Answers

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

A trigger to kill all parts of an enemy? 2 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