How to check if a collider active or not
so i got a gameobject attached with 3 child(at1, at2, at3) which are hitboxes of a weapon, yet the damage of each moveset are different, so i have to know whether the collider is active or not.
the easiest way is to create 3 different script and attached to that child but i dont really want to reuse the code again and again
Answer by FallOutGames4 · Apr 09, 2021 at 12:54 AM
Active / Not Active
if(GetComponent<Collider>()){
// Active
}else{
// Not Active
}
Enabled / Disabled
if(GetComponent<Collider>().enabled){
// Enabled
}else{
// Disabled
}
this is not working bud
[SerializeField]
PolygonCollider2D at1, at2, at3;
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.gameObject.CompareTag("Enemy"))
{
if (GetComponent<at2>().enabled)
{
collision.GetComponent<enemy>().takedamage(40);
Debug.Log("2");
}
if (GetComponent<at3>().enabled)
{
collision.GetComponent<enemy>().takedamage(40);
Debug.Log("3");
}
}
}
the game object is active all time but the collider trigger will only active for sometime(attacking)
Answer by sarvarxba404 · Apr 09, 2021 at 09:22 PM
sometimes the cause of collision failure is at the frame rate. To prevent this, use RaycastHit to check the element between the position of the collision in the previous frame and the position of the collision in the current frame each time.,sometimes the cause of collision failure is at the frame rate. To prevent this, use RaycastHit to check the element between the position of the collision in the previous frame and the position of the collision in the current frame each time.
Maybe