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 Sigillimus · Jun 13, 2013 at 05:20 AM · c#physicstriggerdestructible

[C#] How to destroy a wall next to my trigger?

In my game I'd like for a wall to explode next to my character when he passes through an invisible box collision trigger next to the wall. I have a solid box prefab which spawns broken pieces that will be affected by gravity through a Rigidbody component.

My problem is that I can't connect the trigger to the rest of the code. I admit I'm new to C# so I know I'm probably missing something, but I've been sitting here for about half an hour with little results. I'm building the code off of quill18create's destructible walls tutorial.

TL;DR I need to create an invisible trigger which, when passed through, will replace my solid box with the destructible one.

Here's what I have so far:

 using UnityEngine;
 using System.Collections;
 
 public class Destructable : MonoBehaviour {
     
     public GameObject debrisPrefab;
     public Collider debrisTrigger; 
     
     void OnCollisionEnter (Collision col){
         if(col.gameObject.name == "collapseTrigger")
         {
             Destroy(col.gameObject);
              DestroyMe();
         }
 }
         
     void DestroyMe() 
     {
         if(debrisPrefab) 
         {
             Instantiate(debrisPrefab, transform.position, transform.rotation);
         }
         
         Destroy(gameObject);
     }
 }


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 Sigillimus · Jun 13, 2013 at 04:15 PM 0
Share

I'm still stuck on this for anyone who would be willing to assist. I've tried looking for various different pieces of code to use with little result. I know I'm missing something.

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by AntiLunchBox · Jun 13, 2013 at 05:03 PM

I would throw a Debug statement in that OnCollisionEnter to make sure that is being set off. OnTriggerEnter(Collider other) may be called instead so I would throw that in as well and see if that gets called. If that doesn't work, you may also want to check the collision action matrix since some colliders will not interact with each other: http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html (at the bottom of the page)

And make sure isTrigger is checked on your collider.

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 AntiLunchBox · Jun 13, 2013 at 05:02 PM 0
Share

Oh, and also check if the layer's are configured to collide. In Edit > Project Settings > Physics

avatar image
0

Answer by fafase · Jun 13, 2013 at 05:17 PM

I think the issue is what you destroy, you seem to destroy the trigger but is the trigger the wall you want to go down?

Attach the trigger to the wall to destroy and put this below on the wall/trigger object:

 using UnityEngine;
 using System.Collections;
  
 public class Destructable : MonoBehaviour {
  
 public GameObject debrisPrefab;
  
 void OnTriggerEnter (Collider col){
   if(col.gameObject.name == "collapseTrigger"){
     if(debrisPrefab){
       Instantiate(debrisPrefab, transform.position, transform.rotation);
     }
     Destroy(gameObject);
   }
 }
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

15 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

Related Questions

C# Check Physics.Raycast Once 0 Answers

Problems when i have multiple enemies on the same scene C# 1 Answer

Rigidbody.SweepTest Hit Trigger Colliders 0 Answers

A node in a childnode? 1 Answer

Script calling onCollisionEnter2D and onTriggerEnter2D while disabled 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