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 /
avatar image
0
Question by goosoodude · Sep 23, 2011 at 04:31 PM · fpsaidamage

FPS Tutorial AI robot (AI) Not loosing health.

I made sure that the character controller was formed around his body. I am using the official Unity FPS tutorial Script (CharacterDamage) and it has not been modified. Yes I have unity pro trial.But when i had it in normal it still wouldn't work. The 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 18
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 goosoodude · Sep 23, 2011 at 05:44 PM 0
Share

Seriously. Can i have some help

avatar image goosoodude · Sep 23, 2011 at 08:06 PM 0
Share

Hello? I've been waiting over three hours to have an answer. Sorry for my impatience

avatar image RoughDesign · Sep 23, 2011 at 08:09 PM 0
Share

Doode, it takes longer than 10 $$anonymous$$utes to find this script, and I stopped looking after 10 $$anonymous$$utes. $$anonymous$$aybe you should just post the code here so people can see (& analyze) it without having to download it and then search for which file you mean.

avatar image RoughDesign · Sep 23, 2011 at 08:16 PM 0
Share

Also, it can take even days for a question to be answered. Demanding someone to answer like you do would require to pay that person. The people here do it for free, so your "Hello?" seems quite impolite.

avatar image goosoodude · Sep 23, 2011 at 08:21 PM 0
Share

Sorry the 101010 button is not working. And i didn't mean it in that way. It was like you walk up to a person and you say hello.

Show more comments

2 Replies

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

Answer by J3-Gaming · Sep 23, 2011 at 11:53 PM

Left click:

 function Update()
 {
     if (Input.GetKeyDown(KeyCode.Mouse0))
     {
         ApplyDamage(50.0f);
     }
 }
Comment
Add comment · Show 4 · 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 J3-Gaming · Sep 23, 2011 at 11:55 PM 0
Share

In order to find out your exact problem, we would need to see the weapon script.

This script will be attached to the gun and it calls ApplyDamage (or at least it should for this to work)

avatar image goosoodude · Sep 24, 2011 at 01:22 AM 0
Share

That worked!!! Thank you very much!!!!

avatar image J3-Gaming · Sep 26, 2011 at 08:54 PM 0
Share

Also thumbs it up too, it helps with points here

avatar image goosoodude · Sep 26, 2011 at 09:14 PM 0
Share

I'm not allowed. I just don't have permission

avatar image
0

Answer by RoughDesign · Sep 23, 2011 at 11:12 PM

Everything seems right with the function ApplyDamage...
Insert

function Update () {
if (Input.GetKeyDown ("space")) ApplyDamage(30.0);
}

before it and then test the function, the robot will receive damage everytime you press space in the game.
If that works, your problem is that the function ApplyDamage is not called when the robot is hit.
Then the problem would be in the script of the bullet or weapon.

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 goosoodude · Sep 23, 2011 at 11:49 PM 0
Share

Wait, what if i want to use the left click?

avatar image RoughDesign · Sep 24, 2011 at 08:58 AM 0
Share

This is only to check out if this script is working as it should. Just like the answer from $$anonymous$$ightyGoob, it does ApplyDamage whenever you press the button (no matter where you aim).
In Explosions on page 11 of the tutorial you can see how an explosion calls ApplyDamage in the colliders it touches.

avatar image goosoodude · Sep 24, 2011 at 01:55 PM 0
Share

Oh and thanks for your help too!

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

Ai that applies damage when in range? 1 Answer

Bootcamp damage 0 Answers

Deal damage on collision 2 Answers

zombie ai script 1 Answer

fps tutorial problem 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