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 evildumdum · Sep 07, 2014 at 12:00 AM · javascriptdestroyenemy

Melle system destroy game object not working despite no errors and declining health

so my script was working fine yesterday with no changes, when the enemy has less than health or 0 health it would be destroyed, how ever now the destroy function isn't working, health will go into minuses so i know every thing is working but the destroy bit

down below will be the attack function of my melee system not including animation functions and my enemy health script.

 function Update ()
 {
     if (Input.GetButtonDown("Fire1"))
     {
         //attack animation
         TheMace.animation.Play("MaceSwing");
         //attack function
         var Hit : RaycastHit;
          if (Physics.Raycast (transform.position, transform.TransformDirection(Vector3.forward), Hit))
         {
             Distance = Hit.distance;
             if (Distance < MaxDistance)
             {
                 Hit.transform.SendMessage("ApplyDamage", Damage, SendMessageOptions.DontRequireReceiver);
             }
         }
     }


 #pragma strict
 
 var Health = 100;
 
 function update ()
 {    
     if (Health <= 0)
         {
         Dead();
         }
 }
 
 function ApplyDamage (Damage : int)
 {
     Health -= Damage;
 }
 
 function Dead()
 {
     Destroy (gameObject);
 }


help please :)

Comment
Add comment · Show 1
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 evildumdum · Sep 05, 2014 at 09:59 PM 0
Share

the scripts didn't get separated, function update is my melle system and #pragma scrict is my enamy health script

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Stevenup-7 · Oct 03, 2014 at 11:11 PM

As far as I can see, you are attempting to destroy the separate gameObject property, not the object itself.

Try to replace "Destroy(gameObject)" with:

"Destroy(this.gameObject);" or "Destroy(this.transform);"

This way, you'll destroy the object itself with all what's inside it (for example, childs).

Good Luck!

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Can someone help me fix my Javascript for Flickering Light? 6 Answers

Setting Scroll View Width GUILayout 1 Answer

Enemy sound detection 5 Answers

Countdown code not working 1 Answer

Destroy gameobject 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