Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 11 Next capture
2021 2022 2023
1 capture
11 Jun 22 - 11 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 LudwigVK · Aug 12, 2015 at 06:16 PM · javascriptdestroycomponenthinge joint

destroy hinge joint component from another object in javascript

Hi, you'll see, i have this code, i need to destroy a hinge joint component of a door from the script of a trigger, but when i run the code, it erases the entire door, what am doing wrong or what can i do? i don't want to have a script per door because there are so many of them :I

 #pragma strict
 var levelStuff : GameObject;
 var activar : boolean;
 var mustKill : boolean = false;
 var doorToKill : GameObject;
 var killLevel : GameObject;
 var createSomething : boolean = false;
 var somethingToCreate : GameObject;
 
 function Start () {
 
 }
 
 function Update () {
 
 }
 
 function OnTriggerEnter(col : Collider)
 {
         if(col.gameObject.tag == "personaje")
         {
             if (activar == false)
             {
             levelStuff.SetActive (false);
             Debug.Log("borrado");
             }
             if (activar == true)
             {
             levelStuff.SetActive (true);
             Debug.Log("dibujado");
             }
             
                     if (mustKill == true)
                     {
                         Debug.Log("puerta cerrada");
                         Destroy(doorToKill.GetComponent(HingeJoint)); //<- this is the problem, i think :I
                         Destroy(killLevel);
                     }
                     
                     if (createSomething == true)
                     {
                         somethingToCreate.SetActive(true);
                     }
             
         }
         
 
 }
 
 


Thnks :b

Comment
Add comment
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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by rustofelees · Aug 12, 2015 at 06:26 PM

Just a quick thought, but have you tried commenting out the Destroy(killLevel) line to see if it still destroys the door. Is it possible that your door is a child of what is assigned to killLevel? Also, if this doesn't work, have you tried commenting out both lines to ensure that some other code isn't destroying the door?

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 LudwigVK · Aug 12, 2015 at 06:38 PM 0
Share

yes i tried, it is that piece of code that erases the entire door ins$$anonymous$$d of just deleting the component :I

avatar image rustofelees · Aug 12, 2015 at 06:40 PM 0
Share

Just to be clear it is the Destroy(killLevel) that destroys your door? The problem goes away if you comment that line out?

avatar image LudwigVK · Aug 12, 2015 at 06:48 PM 0
Share

no, it is the Destroy(doorTo$$anonymous$$ill.GetComponent(HingeJoint)); part, if i comment that line out, everything else work just fine, but when i add it back again, it deletes the entire door, not just the hinge joint component :I

avatar image rustofelees · Aug 12, 2015 at 06:53 PM 0
Share

I'd keep breaking the code apart into individual pieces. Can you assign doorTo$$anonymous$$ill.GetComponent(HingeJoint) to a variable and print the result to see if it's as you'd expect?

avatar image
0

Answer by LudwigVK · Aug 12, 2015 at 07:16 PM

oh, i found out what happens: when i destroy the hinge joint, the door falls down... if i also freeze it's rotation & position it should work as i intend, right? to block the door so you can't enter... Thnks :b

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 rustofelees · Aug 12, 2015 at 07:34 PM 0
Share

Sounds like you have a rigid body attached to the door. If so, you should be able to mark it as kinematic and it shouldn't move.

avatar image LudwigVK · Aug 12, 2015 at 08:07 PM 0
Share

tnhks a lot, that did the trick :b

avatar image rustofelees · Aug 12, 2015 at 09:13 PM 0
Share

Glad I could help!

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

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

Related Questions

Instantiate prefabs before it comes into view 0 Answers

Can someone explain the destroy () command? 1 Answer

Destroy cube on collision 1 Answer

Projectile Script Works Until Destroying Projectile 0 Answers

Don'tDestroyOnLoad issue, please help :( 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