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 bpears · Nov 04, 2012 at 04:45 AM ·

Destroy gameObject not working?

 var maximumHitPoints = 100.0;
 var hitPoints = 100.0;
 var deadReplacement : Rigidbody;
 var GOPos : GameObject;
 private var scoreManager : ScoreManager;
 
 function Start(){
 
     var GO = gameObject.FindWithTag("ScoreManager");
     scoreManager = GO.GetComponent("ScoreManager");
 }
 
 function ApplyDamage (damage : float) {
     if (hitPoints <= 0.0)
         return;
 
     // Apply damage
     hitPoints -= damage;
     scoreManager.DrawCrosshair();
     // Are we dead?
     if (hitPoints <= 0.0)
         Replace(); 
 }
 
 function Replace() {
  
     // If we have a dead barrel then replace ourselves with it!
     if (deadReplacement) {
         var dead : Rigidbody = Instantiate(deadReplacement, GOPos.transform.position, GOPos.transform.rotation);
         scoreManager.addScore(100);
         // For better effect we assign the same velocity to the exploded barrel
         dead.rigidbody.velocity = rigidbody.velocity;
         dead.angularVelocity = rigidbody.angularVelocity;
     }
     // Destroy ourselves
     Debug.Log("Calling destroy for " + gameObject);
     Destroy(gameObject);
 }
 
Comment
Add comment · Show 3
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 phodges · Nov 04, 2012 at 06:06 AM 0
Share

Do you see any errors in your console log? Where are you initialising GOPos?

avatar image bpears · Nov 04, 2012 at 05:10 PM 0
Share

No, no errors. The debug for destroy doesnt pop up. Not sure what you mean about GOPos..

avatar image phodges · Nov 04, 2012 at 05:14 PM 0
Share

You have a reference defined to a GameObject called 'GOPos' and are using it to postion your replacement objects. I don't see where that is being set up.

What happens if you put an extra Debug.Log a the top of Replace? Is there any other way in your code of adjusting hitPoints, other than ApplyDamage?

3 Replies

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

Answer by bpears · Nov 04, 2012 at 06:32 PM

Thanks everyone. Problem was not my destroy script, it was that the dead body that replaces it did not have a destroy script. "DOH!" Now it works perfect. :)

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
avatar image
1

Answer by deltamish · Nov 04, 2012 at 06:25 AM

what is the problem you face you need to be brief about your problem and what fix you want

Dont use speech marks to get componenet

 GO.GetComponent(ScoreManager); correct

 GO.GetComponent("ScoreManager"); wrong
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 bpears · Nov 04, 2012 at 04:47 PM 0
Share

O$$anonymous$$, this did help some. It at least got the debug to show up. But the dead enemy is still there.I want the dead enemy to vanish after some time.

avatar image
0

Answer by soulburner · Nov 04, 2012 at 04:49 PM

GameObject.Destroy(go);

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 bpears · Nov 04, 2012 at 05:13 PM 0
Share

This does not make sense? Just causes error about unidentified (go)

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

13 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

Related Questions

Multiple Cars not working 1 Answer

Climbing script 0 Answers

My character will fall through the floor with this script:... 1 Answer

DamageScript 1 Answer

Help Solve This 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