- Home /
 
 
               Question by 
               AsAnAsterisk · Jun 22, 2017 at 08:02 PM · 
                animationcolliderscollision detection  
              
 
              How to activate a collider only for a certain animation, and then deactivate it
I have a collider attached to my weapon, (In a child gameobject) and would only like it activated during the attack animation and not when the player is just idling, however I don't know how I would phrase the scripting to achieve such an effect.
 public class Hand : MonoBehaviour {
 
     private Animator anim;
     public CapsuleCollider cc;
 
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animator>();
 
         cc.enabled = false;
     }
     
     // Update is called once per frame
     void Update () {
         if (Input.GetButton("Fire1"))
         {
             anim.SetBool("IsNoInput", false);
             anim.SetBool("IsAttacking", true);
 
         }
         else
         {
             anim.SetBool("IsNoInput", true);
             anim.SetBool("IsAttacking", false);
         }
         
         if (anim.SetBool("IsAttacking", true)); 
         {
         cc.enabled = true; 
         }
         
         
      }
         
         
     public void ActiveCollider(int active)
     {
         if (active == 0)
             cc.enabled = false;
         else
             cc.enabled = true;
     }
 
    }
 
               This current script leads to an "cannot implicitly convert type 'void' to 'bool'" error.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by BattiestMist · Jun 23, 2017 at 12:59 AM
Your script should work fine except for a small error.
 if (anim.SetBool("IsAttacking", true));
 
               should be:
 if (anim.GetBool("IsAttacking") == true)
 
               Other than that, it seems like it would work just fine.
Your answer