Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

cant enable a 2d box collider

Discussion in '2D' started by Mark_Wilson, Aug 12, 2014.

  1. Mark_Wilson

    Mark_Wilson

    Joined:
    Jan 6, 2013
    Posts:
    112
    Hey guys, I have a 2d box collider which I need to be enabled only when another sprite becomes visible.
    So in an if statement which sets a boolean to true I want to say boxcollider2d. enabled =false/true.

    Sounds simple enough but .enabled is not coming up as an option. I'm a bit confused as this has worked before and seems to be the only way to do what I need.
    My script which I want to enable the collider in is part of a child game object along with the 2dboxcollider.

    I've also tried making the size 0, 0 but the .size option isn't available either.

    Can anyone help me out?
    Cheers guys.
     
  2. cbothra

    cbothra

    Joined:
    Mar 14, 2014
    Posts:
    125
    I've tried this and worked for me like following:
    Code (CSharp):
    1. this.gameObject.GetComponent<BoxCollider2D> ().enabled = false;
    If you can paste a part of your code where you've tried to do this?
     
  3. Mark_Wilson

    Mark_Wilson

    Joined:
    Jan 6, 2013
    Posts:
    112
    Ah, i've never seen it done that way, i'll give it a go.
    Cheers
     
  4. Mark_Wilson

    Mark_Wilson

    Joined:
    Jan 6, 2013
    Posts:
    112
    that done the trick! cheers dude :)