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 Leroterr · May 22, 2014 at 01:05 PM · collisioncollidertriggerstaticclone

Multiple colliders on one object? Or changing variables on a specific clone.

I have this cloned object with 2 colliders. One small one, and one big one.

When the big one gets hit, something happens on the parent script, and when the small one gets hit, something different happens on the parent script.

I've already tried making a child object and inserting the 2nd collider there, but since the objects are cloned, when the 2nd collider gets hit on this specific clone, the other colliders for the other clones detect it as well (Since I had to make it static, because it was a child object changing variables on the parent object's script).

So what is the best way to fix this?

I need something to prevent the parent variable from being changed when some other collider gets hit. Only the said collider's parent should detect it, not the other parents.

Here's my code so you guys could understand:

Parent

 using UnityEngine;
 using System.Collections;
 
 public static bool colorRed;
 
 public class Parent : MonoBehaviour {
 
     if(colorRed)
         {
             Debug.Log ("Red");
         }

     else
         {
             Debug.Log ("Blue");
         }
 
 }

Child #1

 using UnityEngine;
 using System.Collections;
 
 public class Child1 : MonoBehaviour {
 
 void OnTriggerEnter(Collider col) {
 
         //If it hits Child1
         if (col.gameObject.CompareTag ("colorThing"))
         {
             //Make it Red
             Parent.colorRed = true;
         }
 
 }

Child #2

 using UnityEngine;
 using System.Collections;
 
 public class Child2 : MonoBehaviour {
 
 void OnTriggerEnter(Collider col) {
 
         //If it hits Child2
         if (col.gameObject.CompareTag ("colorThing"))
         {
             //Make it Blue
             Parent.colorRed = false;
         }
 
 }

So what happens here is, when Child1's collider gets hit, red happens on parent, and when Child2's collider gets hit, blue happens on parent.

The problem is, the objects are cloned many times.

When the red one gets hit for this specific clone, the parent of ALL the clones gets red. What I want is, when the specific clone gets red, it's the only one that gets red, not the other clones.

This could be fixed if I can just have multiple colliders on one object that does 2 different things when the same object collides with them, so I don't have to make the bool colorRed static.

Thanks for the help :)

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

1 Reply

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

Answer by HarshadK · May 22, 2014 at 01:35 PM

Try 'this' keyword to call the parent of a specific clone object.

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 Leroterr · May 22, 2014 at 01:42 PM 0
Share

===EDIT===

Never$$anonymous$$d, got it to work now, thanks!

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

20 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

Related Questions

How do you execute Trigger-collider collision only in one gameobject? 1 Answer

How to make work a collision when is invisible? 3 Answers

Check if trigger is occupied 1 Answer

Triggering platform animation on colliding with Button 0 Answers

NPCs collide with collider but player does not 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