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 adamchakov · Feb 25, 2014 at 01:50 PM · colliderdestroybox

make collider enabled when another object is destroyed

hey guys , how do i make a sphere collider enabled when another object tagged as "TNT" is destroyed , i have this variables but i dunno how to group them into a script , im quit noob at coding , can anyone help me please ? thanks ! (the sphere collider is in an empty object)

if (other.CompareTag("TNT")){ Destroy(other.gameObject); collider.enabled = false;

Comment
Add comment · Show 4
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 fafase · Feb 25, 2014 at 02:18 PM 0
Share

So the TNT gets destroyed, I guess you have that part, and you want a sphere collider to get enabled, is that collider attached to the TNT object? Is there a lot of this in your game? If you plan on having many TNT objects, are they all connected to one collider of their own or do they need to figure out the closest one or else?

Finally, what are you doing with the collider? because you might be going to wrong way, for instance if your collider is meant to be used for the explosion (just mentionning). That is quite a few questions but they should help us help you (now I sound like a school counselor).

avatar image adamchakov · Feb 25, 2014 at 03:25 PM 0
Share

hey @fafase thanks for your help i really appreciate it , now what i want of ALL of this , my concept is to create like a chain reaction (explosions),i have TNT(1) and TNT(2) (near TNT(1)) , there's an emptyobject that have two childs which are the TNT(1) and an emptyobject that has a spherecollider, i want when TNT(1) gets exploded(destroyed) a spherecollider of an emptyobject will be enabled, , i want the spherecollider to be enabled when TNT(1) gets destroyed , and when the spherecollider will be enabled , the TNT(2) will trigger the spherecollider , and TNT(2) will be destroyed too , that's all , hope you will understand my concept , thanks !

avatar image fafase · Feb 25, 2014 at 03:51 PM 0
Share

ok if you have those two TNT only (and even if you have more), you can do it another way. Now considering TNT1 will always trigger TNT regadless the distance, you don't need the sphere:

 public class TNTScript:$$anonymous$$onoBehaviour{
    public GameObject otherTNT;
    void Explosion(){
       // Here particle system and destroy
       if(otherTNT != null)
           otherTNT.GetComponent<TNTScript>().Explosion();
   }
 }

Place this script in both TNTs. Drag TNT2 into the slot in the inspector of TNT1 and this is it.

Now if there should be a check for distance and find any TNT within range (some ind of Angry Birds system), then you better have an array or list of TNT boxes, then when one is exploding, check if there are nay within range and make them explode as well. They will also look for TNT in range and will in turn call for explosion and so on.

avatar image adamchakov · Feb 25, 2014 at 03:55 PM 0
Share

@fafase thanks for the reply dude , yeah my point is the "RANGE" , i want to use the spherecallider as a "RANGE" to destroy another TNT which is in that range , not all the TNT's that are in the scene .

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by DoctorMoney · Feb 25, 2014 at 03:40 PM

We might need more code to understand exactly what you want and how you're going about it but for starters:

 collider.enabled = false;

should be

 collider.enabled = true;

if it's false then you're disabling the 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 adamchakov · Feb 25, 2014 at 03:44 PM 0
Share

DUUUUUUUUH dude this is obvious i already know that false is for disabling the collider and true for enabling , i just mentioned that in my question to let people know that im doing a progress not just sitting there and waiting for an answer

avatar image
0

Answer by fafase · Feb 25, 2014 at 04:15 PM

 public class TNTScript:MonoBehaviour{
     static List<TNTScript> list = new List<TNTScript>();
     public bool exploding = false;
     void Start(){
        list.Add(this);
     }
     void Explosion(){
        for (int i = 0; i < list.Count; i++){
           float dist = (transform.position - list[i].transform.position).sqrMagnitude;
           exploding = true;
           if(dist < range && list[i].exploding == false){
               list[i].GetComponent<TNTScript>().Explosion(gameObject);
           }
        }
        list.Remove(gameObject);
        Destroy(gameObject);
     }
 }

Ok, so you need to try that as I cannot. The idea is that the list gathers all of the TNT boxes, you could do it in a way that you avoid static for the sake of time, I will do it this way.

The method iterates through the list and checks for any object that would be close enough. If so, it calls the Explosion on the other box.

To avoid TNT boxes to call it each other endlessly the exploding boolean is set and check.

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

21 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

Related Questions

Internal collisions 1 Answer

Something wrong with destroying script 0 Answers

Making a bullet invinceble 0 Answers

How did I screw up BoxColliders? 1 Answer

col.gameObject.layer is not working 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