So I made a script which is attached to a GameObject, that codes when the “G” Key is pressed it will play an animation and enable/disable the Polygon Collider 2D.
– How can I make it when the ”G” Key is pressed it plays the animation and at the beginning of the animation it enables the Polygon Collider 2D, and at the end of the animation is disables the polygon Collider
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<PolygonCollider2D>();
myAnimator = GetComponent<Animator>();
}
// 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);
}
}
}