I want to set the attack range and the object body collider in one object (by some reason).
i find the code of"other.GetType () == typeof(CapsuleCollider2D)"
but it can not solve my problem.
Is there any method for condition of this object’s Collider type??
e.g.If my main object is 1
I can collision the 2 and 3
How can i do it collision 1 and 3…thankyou bro…
Hm I don’t understand your question fully… what do you exactly want. Is the Attack Range just a Trigger and the inner Collider2D is a normal Collider2D?
for different types of Collider you could use this:
void OnCollisionEnter2D(Collision2D other){
if(other.collider == GetComponent<CircleCollider2D>()){
//do stuff
}
if(other.collider == GetComponent<CapsuleCollider2D>()){
//do stuff
}
if(other.collider == GetComponent<BoxCollider2D>()){
//do stuff
}
}
// and for Trigger Enter. Trigger must be activated in Inspector
void OnTriggerEnter2D(Collider2D other){
if(other == GetComponent<CircleCollider2D>()){
//do stuff
}
if(other == GetComponent<CapsuleCollider2D>()){
//do stuff
}
if(other == GetComponent<BoxCollider2D>()){
//do stuff
}
}