- Home /
Animations Problem
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<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);
}
}
}
Add this to your void Start() { myPolygonCollider2D.enabled = false; } that will disable the collider when editor is started.
Answer by SteenPetersen · Aug 20, 2017 at 07:54 PM
In the Editor simply disable the Polygon collider so that it is disabled at start.
alternately add this to start:
myPolygonCollider2D.enabled = false;
then you could make a function like this:
public void MyFunction(){
myPolygonCollider2D.enabled = false;
}
and then in your animation simply make an animation event (https://docs.unity3d.com/Manual/animeditor-AnimationEvents.html) and call that function right at the end of the animation
Your answer

Follow this Question
Related Questions
Playing 2 animations at the same time 2 Answers
Skew animation 0 Answers
Fast-forwarding an animation to its last frame 2 Answers
Play and Stop Animation 1 Answer
Gun script help 1 Answer