• 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 Ifxhitsy · Jun 30, 2014 at 03:02 PM ·

If x (Object) hits y (Wall 1) then activate z (Wall 2+3) ?

I have a (probably easy to solve) problem with the following script:

 #pragma strict
 
 function OnCollisionEnter2D (col : Collision2D)
 {
     if(col.gameObject.name == "Test")
         col.gameObject.GetComponent(BoxCollider2D).enabled = true;
 }

I assigned this script to a "Wall 1" gameObject with a BoxCollider2D which is activate with no trigger function. The "Test" gameObject has an activate Collider2D with no trigger function and a Rigidbody2D. I also have "Wall 2" and "Wall 3" also with a BoxCollider2D but not activate and no trigger function.

I want "Wall 2" and "Wall 3" to be activated/enabled when "Test" touches "Wall 1" so "Test" can not pass "Wall 2" and "Wall 3".

I tested the above script without linking "Wall 1" to "Wall 2" and "Wall 3" and temporarily deactivated the BoxCollider2D of "Wall 1" just to test if the script is even working... well it does not work. "Wall 2" and "Wall 3" should only be active for the specific "Test" gameObject.

I am a completely beginner to Unity and I am working on my first (test) game. Can someone help me out with my problem? Would be very nice so I can develope further. :)

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 Ifxhitsy · Jul 02, 2014 at 04:55 PM 0
Share

Could anyone help me out with this problem? Or is there a similar problem someone had and got answered?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by K_Fi · Jul 02, 2014 at 06:48 PM

I'm not sure I can give you an answer but I can help you out with something I found useful as a beginner. For debugging, using print("The thing happened") or whatever (Or a variable if you want to test whether it is what it should be) to make sure a part of your code is happening.

  1. Put it within your function and if you don't see it in the console, the collision isn't registering (This could be for a number of reasons, but at least you've narrowed down your search.) I have no experience with 2d colliders, sorry.

  2. Put it within your conditional and if you don't see it in the console, the if statement isn't returning as true (This could be for a number of reasons, but at least you've narrowed down your search.) Perhaps try the statement if(col.transform.name == "Test") or double check to see if the name Test is capitalized.

  3. Put print(col.transform.name) to make sure the name of the object is Test.

Number 2 might be it, I've always accessed a gameobject's name through it's transform but a skim through the documentation suggests that that doesn't need to be the case.

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 Ifxhitsy · Jul 13, 2014 at 02:00 PM 0
Share

Thanks for your advice. But I am still looking for a solution.

Should I use something different ins$$anonymous$$d of OnCollisionEnter2D? Is .enabled even something I need here or should I use something else?

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

3 People are following this question.

avatar image avatar image avatar image

Related Questions

AnimationEvent, Collider, OnTriggerEnter logic? 0 Answers

trouble adding script to clone object 1 Answer

After launching game on Windows x32 the script working with MySQL database could not be instantiated 0 Answers

Accessing external scripts (yet again) 2 Answers

Why do I need a rigidbody for onmouseover? 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