• 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
Question by Cheetoturkey · Jun 11, 2013 at 11:09 PM · fpsenemyrespawnenemyairespawning

whats wrong with my enemy respawn script????

alt textwhen the enemy respawns the scripts attached to it get unchecked and dont work heres my script on the enemy #pragma strict

 var health = 100;
 var respawn : Transform;
 var enemy : Transform;
 function TakeDamage (damage : float)
 {
     if (health <= 0)
     {
         Destroy(gameObject);
         return;
     }
     health -= damage;
     if (health <= 0)
     {
         Destroy(gameObject);
         health += 100;
         var respawnedEnemy : Transform = Instantiate( respawn, enemy.transform.position, enemy.transform.rotation );
     //respawnedEnemy.velocity = transform.TransformDirection(Random.Range(-2, 2) - 3.0f, Random.Range(-1, 2) + 3.0f, -Random.Range(-2, 2) + 1.0f);
     Physics.IgnoreCollision( respawnedEnemy. collider, transform.root.collider );
        
     }
 }

and my script on the bullet #pragma strict

 var damage : int = 25;
 
 function Start () {
     Destroy (gameObject, 4);    
 }
 
 function OnCollisionStay (theObject : Collision) 
 {
     if(theObject.gameObject.tag=="Enemy")
     {
         theObject.gameObject.GetComponent(EnemyHealth).TakeDamage(damage);
     }
 }


help.png (32.5 kB)
Comment

People who like this

0 Show 0
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
Best Answer

Answer by Skalde · Jun 11, 2013 at 11:23 PM

Instead of using the prefab as the "Enemy : Transform" i would suggest that you create a new enemy Away from your scene your terrain, and uses that because, Prefabs doesnt check the variables when its created.. its a wierd system but thats how i did it ^^

did this make sense??

Comment

People who like this

0 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 Cheetoturkey · Jun 11, 2013 at 11:38 PM 0
Share

the problem is it isnt a prefab i updated the question though with a picture of whats happening

avatar image Skalde · Jun 12, 2013 at 01:51 AM 0
Share

Strange.. when i did this, i made the enemy instatiate an "emty gameobject" i called "Respawner" and put a script on it that yield for 300 Seconds and then instatiated the enemy. then i put a "Enemy doll" and a "Respawner" in the scene far away from the Terrain and instatiated from them..

try that?

avatar image Cheetoturkey · Jun 12, 2013 at 01:38 PM 0
Share

nevermind i got it working all i had to do was add my other scripts on the enemy into one big script then make that script enabled when the enemy is respawned #pragma strict

 var moveSpeed : int;
 var turnSpeed : int;
 var health : int = 200;
 var respawn : Transform;
 var target : Transform;
 var projectile : EnemyHealth;
 
 function TakeDamage (damage : int)
 {
     health -= damage;
     if (health <= 0)
     {
         Destroy(gameObject);
         return;
     }
     health -= damage;
     if (health <= 0)
     {
         Destroy(gameObject);
         health += 200;
         RespawnEnemy();
        
     }
 }
 
 function RespawnEnemy()
 {
  var respawnedEnemy : EnemyHealth;
  respawnedEnemy = Instantiate(projectile, respawn.transform.position, respawn.transform.rotation);
  respawnedEnemy.turnSpeed = 10;
  respawnedEnemy.moveSpeed = 10;
  respawnedEnemy.enabled = true;
  var other : EnemyHealth = gameObject.GetComponent(EnemyHealth);
     //respawnedEnemy.velocity = transform.TransformDirection(Random.Range(-2, 2) - 3.0f, Random.Range(-1, 2) + 3.0f, -Random.Range(-2, 2) + 1.0f);
     Physics.IgnoreCollision( respawnedEnemy. collider, transform.root.collider );
        
 }
 
 function OnGUI()
 {
     GUI.Box(Rect(Screen.width - 300, 40, 100, 80), "");
     GUI.Label(Rect(Screen.width - 300, 70, 90, 20), "health:" + health);
 }
 
 
 
 // follow our player
 function Start()
 {
     target = GameObject.FindGameObjectWithTag("Player").transform;
 }
 function Update()
 {
     transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(target.position - transform.position), turnSpeed * Time.deltaTime);
 
 if(Vector3.Distance(transform.position, target.position) > 10)
 transform.position += transform.forward * moveSpeed * Time.deltaTime;
 }

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

15 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

Related Questions

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

I need help creating a ZombieAI for my Walking Dead Game 0 Answers

Shooting and health Help 0 Answers

How to make an enemy respawn? 0 Answers

Enemy Respawn causes player to unable to attack 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