Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 /
This question was closed Jul 23, 2011 at 07:42 PM by Jason B for the following reason:

Too subjective and argumentative

avatar image
-1
Question by goosoodude · Jul 21, 2011 at 03:28 PM · damagefpstutorial

FPSTutorial: AI robot not taking any damage

Hi! This is a followup to the last question. I have used all of the official tutorial resources and PDF document. But, I just cant get the robot to take any damage! It will first run in place the other way from me, then when I shoot it, it doesn't die! I've tried to add a box collider and numerous things, but it just doesn't do a darn thing! Thank you! Oh yeah, here's my script:

 var hitPoints = 100.0;
 var deadReplacement : Transform;
 var dieSound : AudioClip;
 
 function ApplyDamage (damage : float) {
     // We already have less than 0 hitpoints, maybe we got killed already?
     if (hitPoints <= 0.0)
         return;
 
     hitPoints -= damage;
     if (hitPoints <= 0.0)
     {
         Detonate();
     }
 }
 
 function Detonate () {
     // Destroy ourselves
     Destroy(gameObject);
     
     // Play a dying audio clip
     if (dieSound)
         AudioSource.PlayClipAtPoint(dieSound, transform.position);
 
     // Replace ourselves with the dead body
     if (deadReplacement) {
         var dead : Transform = Instantiate(deadReplacement, transform.position, transform.rotation);
         
         // Copy position & rotation from the old hierarchy into the dead replacement
         CopyTransformsRecurse(transform, dead);
     }
 }
 
 static function CopyTransformsRecurse (src : Transform,  dst : Transform) {
     dst.position = src.position;
     dst.rotation = src.rotation;
     
     for (var child : Transform in dst) {
         // Match the transform with the same name
         var curSrc = src.Find(child.name);
         if (curSrc)
             CopyTransformsRecurse(curSrc, child);
     }
 }
Comment
Add comment · Show 2
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 Chris D · Jul 21, 2011 at 03:56 PM 0
Share

Everything should work properly right off the bat. Have you changed anything? Try re-downloading and opening the project.

avatar image goosoodude · Jul 23, 2011 at 07:29 PM 0
Share

so what i do is delete the first one? in the original script or the script in the other quesiton?

2 Replies

  • Sort: 
avatar image
3

Answer by Kith · Jul 22, 2011 at 07:31 PM

     if (hitPoints <= 0.0)
     return;

This looks like it would be the problem. You're checking to see if(hitPoints

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 aldonaletto · Jul 23, 2011 at 07:25 PM 0
Share

The first if avoids the enemy to die again; if hitPoints>0 it's alive and can be hit. After receiving the damage, the second if checks if this damage killed the enemy.

avatar image
-3

Answer by goosoodude · Jul 22, 2011 at 08:26 PM

so, i need help, can you please post the whole code the way it is supposed to be?!?!?!?!?!?

Comment
Add comment · Show 17 · 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 Chris D · Jul 22, 2011 at 08:32 PM 2
Share

Please do not post comments or questions as answers. @$$anonymous$$ith has provided what looks like the correct solution; take a second to try to parse the meaning out of his string of words. If you can't figure it out, consider trying a more basic program$$anonymous$$g tutorial.

avatar image goosoodude · Jul 22, 2011 at 08:34 PM 0
Share

seriously, please! I just need the script. I am not a very good scripter!

avatar image Chris D · Jul 22, 2011 at 08:49 PM 1
Share

...@$$anonymous$$ith has literally listed the answer; just eli$$anonymous$$ate that code. I understand you're not the greatest scripter but you've gotta think about these things if you want to improve. Otherwise you're going to be here for every problem you have.

avatar image goosoodude · Jul 22, 2011 at 09:20 PM 0
Share

I'm sorry to burst your bubble, but I know how to move, I know a lot of things about Unity3D. Oh yeah, that was not the answer! I deleted that part of the code and it said "All compiler errors have to be fixed to enter playmode!"

avatar image Kith · Jul 22, 2011 at 09:43 PM 2
Share

You're making it very difficult for us to help you. "All compiler errors have to be fixed to enter play mode". Yes, we know this. Can you tell us what your error is? Open up your console and see what it says. I'm sorry, but unless you're willing to pay me, I'm not going to write the script for you. If you're serious about learning how to program well, you're going to have to increase your problem-solving skills. I'll be happy to point you in the right direction, but this isn't a place for you to ask people to write your code for you.

So, what is the error? Because I assure you, the problem you were having before was due to that if statement you deleted.

Show more comments

Follow this Question

Answers Answers and Comments

6 People are following this question.

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

Related Questions

FPS Tutorial AI Damage not Working 1 Answer

on collision damage 1 Answer

Quick question about DamageReceiver script from FPS tutorial 1 Answer

FPSTutorial: AI robot not taking any damage! 2 Answers

AIs with guns and sentrys that fire 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