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 portal17 · Nov 08, 2012 at 03:40 AM · aidestroyenemy

Need help with AI script

Hello...I need some help with my script, my player can shoot fireballs and can respawn when it touches the enemy, but if i duplicate my enemy and destroy one of them, both of them are destroyed. If anyone knows whats wrong with my script so only one enemy gets destroyed, please help. Heres my script:

 #pragma strict 
 var health = 10;
 var TakeDamage : boolean;
 
 function OnTriggerEnter(other : Collider){
     if(other.tag == "Player"){
       TakeDamage = true;
     }
 }
 
 function OnTriggerExit(other : Collider){
     if(other.tag == "Player"){
       TakeDamage = false;
     }
 }
 
 function Update(){
     if(TakeDamage){
       if(Input.GetButtonDown("Fire1")){
           health --;
         }
     }
     if(health<= 0){
     print("Enemy Down");
     health = 0;
     Destroy(gameObject);
     }
 }

 
Comment
Add comment · Show 4
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 harschell · Nov 08, 2012 at 05:45 AM 0
Share

@portal17 Explain briefly didn't get properly what you are trying to ask??

avatar image CodeMasterMike · Nov 08, 2012 at 06:48 AM 1
Share

Can you post the code where you duplicate your enemy as well?

avatar image Chimera3D · Nov 08, 2012 at 07:12 AM 0
Share

It seems like they are somehow sharing the same values for the health variable or the take damage variable... how are you duplicating the enemies and are they inside of each other or something like that?

avatar image Seth-Bergman · Nov 08, 2012 at 07:58 AM 0
Share

you probably checked "Take Damage" on your enemy, make sure it is unchecked to start

2 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by prototype7 · Nov 08, 2012 at 07:56 AM

Try this maybe it works,

 #pragma strict 
 var health = 10;
 var TakeDamage : boolean;
 var myCollider : Collider;
 
 function OnTriggerEnter(other : Collider){
     if(other.tag == "Player"){
       TakeDamage = true;
     }
     myCollider = other;
 }
 
 function OnTriggerExit(other : Collider){
     if(other.tag == "Player"){
       TakeDamage = false;
     }
 }
 
 
 function Update(){
     if(TakeDamage){
       if(Input.GetButtonDown("Fire1")){
           health --;
         }
     }
     if(health<= 0){
     print("Enemy Down");
     health = 0;
         if(myCollider != null)
         {
         Destroy(myCollider.gameObject);
         }
     }
     
 }
Comment
Add comment · 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 prototype7 · Nov 09, 2012 at 03:03 AM 0
Share

Did you make it mate ? you can change "myCollider" to "enemyHit" to make more sense, so if your fireballs hit/collide the enemy it will recognized the enemy and save it into enemyHit = other in function OnTriggerEnter. and Destroy only that enemy in Destroy(enemyHit.gameObject).

avatar image harschell · Nov 09, 2012 at 05:28 AM 0
Share

@prototype7 he he You begging to accept answer ???????? :P Not good...........

avatar image prototype7 · Nov 10, 2012 at 02:51 AM 0
Share

Thanks.... try to shoot the box with your left mouse click.-->

avatar image
0

Answer by Mensley · Nov 20, 2012 at 07:29 AM

hi What did you put the script on enemy or caracter plzz answer as i am having the same trouble

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 prototype7 · Nov 22, 2012 at 07:45 AM 0
Share

i attached sample package in my comment above, try to explore the Capsule->Camera->Launcher on Hierarchy view

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

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

enemy ai going to player 2 Answers

how can i destroy a cube when i press a gui button??? 1 Answer

C# AI, Enemy is flying at me when I jump. 2 Answers

How to make a Tron Light cycle Enemy AI Script ? 0 Answers

Enemy AI help. 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