- Home /
How to enable/disable polygoncollider2d using script?
I have tried this for enabling and disabling polygon collider but its not working:
void OnTriggerEnter2D(Collider2D obj) { if (obj.tag == "Player") { mirror1.GetComponent().enabled = mirror3.GetComponent().enabled = false; mirror2.GetComponent().enabled = true;
mirror1.GetComponent<PolygonCollider2D>().enabled =
mirror3.GetComponent<PolygonCollider2D>().enabled = false;
mirror2.GetComponent<PolygonCollider2D>().enabled = true;
}
}
Answer by RocketFriday · Dec 10, 2017 at 01:03 PM
You can't tell it what to get and what to do with it all in one line.
GameObject mirror1;
PolygonCollider2D col1;
Awake(){
col1 = mirror1.GetComponent();
}
Start(){
col1.enabled =
}
Your answer
Follow this Question
Related Questions
What's better to use: Collider tilemap 2D or edge collider? 0 Answers
OnTriggerEnter2D not working 2 Answers
How can you change a colliders shape on collision with another collider? 1 Answer
Why is there a gap between my player and the wall during wall slide? SOLVED 2 Answers
Use transform.position in FixedUpdate to ensure collision with objects which have Velocity 0 Answers