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. :slight_smile:

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.