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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by Cubie30DiMH · May 12, 2015 at 10:50 AM · destroy object

How do I destroy an object with a trigger?

I'm trying to have a player walk over a pressure plate trigger and have that cause a door to destroy itself, but I can't figure out the code for it. I'm also really new to Unity, and programming in general, so I think I'm trying to do something out of my skill set. The two ways I've tried are:

else if(trigger.name == "PressurePlate6") { Destroy(GameObject.name("Lockout")); } else if(trigger.name == "PressurePlate7") { GameObject("BoulderTrapDoor").isCollider = false; }

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 Nerevar · May 12, 2015 at 12:01 PM 0
Share

did you check the documentation example? You have a video about colliders/triggers here.

If you still have questions after that, I'll try to help further.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Eudaimonium · May 12, 2015 at 01:04 PM

To what is this script attached, I assume the player?

If you need to destroy an object named "Lockout", make a public variable outside the function, and assign the door's gameobject to it via the Inspector. Example: public GameObject lockoutDoor;

and then within your function: Destroy(lockoutDoor);

Same with the drapdoor object. Use as much Inspector assigning where possible. Otherwise, try to find all the gameObject within your "Start" function, and in Update only access the saved objects.

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
0

Answer by itsmealex100 · May 12, 2015 at 12:50 PM

Hi, first off this site is great for getting better with programming you'll be fine after a few months of experience.

Okay, this is how I would do it.
1. Tag your player with "Player". 2. Make sure the player is NOT set to IsTrigger. 3. Put this script on your PressurePlate.

 public GameObject door; // This is where you reference the door you want to destroy
 
 void OnCollisionEnter(Collision other) {
 
 if(other.tag == "Player") {
 Destroy(door);
 Destroy(gameObject);  //This will destroy the pressure plate after it has been triggered 
 }
 }









Comment
Add comment · Show 2 · 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 bestweegee · Apr 11, 2019 at 08:37 PM 0
Share

other.tag doesn't work

avatar image Hellium bestweegee · Apr 11, 2019 at 09:10 PM 0
Share
 void OnCollisionEnter(Collision collision)
 { 
      if(collision.gameObject.CompareTag("Player")) {
          Destroy(door);
          Destroy(gameObject);  //This will destroy the pressure plate after it has been triggered 
      }
 }

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

7 People are following this question.

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

Related Questions

Javascript. Respawning a character after destroyobject(). 0 Answers

destroy prefabs 1 Answer

Trouble with upgrading towers 1 Answer

Destroy Clone when colliding with 2d box collider 0 Answers

2d edge collider wont destroy? 0 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