Animation Problems

I made a script that enables/disables the Polygon Collider 2D component when the ‘‘g’’ key is pressed. This script is attached to a GameObject called Indingo(The Player). So when the “g” key is pressed the script enables or disables the Polygon Collider 2D and plays the animation.

What I want: I want the Polygon Collider 2D to be disabled at the beginning. Meaning I want the Polygon Collider 2D to be disabled at the start of the game, and for the Polygon Collider 2D to be enabled when the animation starts and be disabled when the animation ends all when the ‘‘g’’ key is pressed.


using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Indingo_Lava_Burst_Activator_Deactivator : MonoBehaviour
{

private PolygonCollider2D myPolygonCollider2D;
private Animator myAnimator;

// Use this for initialization
void Start()
{
myPolygonCollider2D = GetComponent();
myAnimator = GetComponent();
}

// Update is called once per frame
void Update()
{
if (Input.GetKeyUp(KeyCode.G))
{
myPolygonCollider2D.enabled = !myPolygonCollider2D.enabled;
myAnimator.SetBool(“attack”, true);
}
else
{
myAnimator.SetBool(“attack”, false);
}
}
}

Okay so I would do something like disable the collider initially. (You can do this manually or through your code in your awake or start functions) Then you will need to do something like:

// PSEUDO CODE
IF > COLLIDER is ACTIVE IN HEIRARCHY
THEN DO > (Your Current If Statement)
ELSE >
Return;