Search Unity

Wait x seconds before a collider is set to true?

Discussion in 'Scripting' started by DefinitivNichtSteffi, Jul 26, 2017.

  1. DefinitivNichtSteffi

    DefinitivNichtSteffi

    Joined:
    Jul 10, 2017
    Posts:
    1
    Hi there,
    First of all i am german so in my Script there is some german language but you can ignore that.
    I have a CapsuleCollider2D , which enables after a Key is pressed and a Animation started. How can i
    enable the Capsule Collider x seconds after the animation started? I hope you can help me and sorry for my bad english ^^".
    Code (CSharp):
    1. //Attack
    2.         if (Input.GetKey(KeyCode.Mouse0))
    3.         {
    4.             // Attack Animation abspielen
    5.             playerAnimator.SetBool("Attack 2", true);
    6.             //Schwert Collider aktivieren
    7.             attackCollider.enabled = true;
    8.         } else{
    9.             playerAnimator.SetBool("Attack 2", false);
    10.             attackCollider.enabled = false;
    11.             if (playerAnimator == false);
    12.         }
    13.  
    14.     }
     
  2. cstooch

    cstooch

    Joined:
    Apr 16, 2014
    Posts:
    354
    If you want the collider to activate DURING animation, then I'd suggest an animation event. But if not,maybe it would still work if you just call a coroutine after animation ends that delays until you want it to turn the collider on, for example.