1

I have a character game object, with both an animator and a collider.

Whenever the animator is on, the collider cannot be changed during run-time, though it can be changed in scene editing mode, via the inspector.

No matter what animator properties I change via the inspector, nothing happens. The feature I've tried to fix was invincibility frames - A co-routine, disabling the character's hit-box for several seconds.

I attempted enabling and disabling the collider's isTrigger property, but the problem persisted - The character still gets hurt while the isTrigger is on.

Code:

private IEnumerator ActivateInvincibility()
    {
        // 3 seconds of invincibility
        _hit_zone.enabled = false;  // no effect
        _hit_zone.isTrigger = true;  // no effect either
        yield return new WaitForSeconds(3f);
        _hit_zone.enabled = true;
        _hit_zone.isTrigger = false;;
    }

Called normally, like so: StartCoroutine("ActivateInvincibility");.

Edit:

For clarification, what I want to know is the root of the problem I've encountered, because I suspect more problems could occur because of this one root.

I have also edited out the unimportant lines of code.

Blawnode
  • 13
  • 1
  • 5

1 Answers1

0
//Added control flag
private bool isInvincibility = false;

private IEnumerator ActivateInvincibility()
{
    isInvincibility = true;
    //wait time
    isInvincibility = false;
}

void OnCollisionEnter(Collision collision)//or trigger {
     if(!isInvincibility && */Your condition tag name etc/*){
        //Damage ?
     }
}

psdt; call coroutine as StartCoroutine(ActivateInvincibility());. Don't use string name.

Ali
  • 1,055
  • 9
  • 17
alex
  • 11
  • 3
  • This does work, but I still do want to know what caused the problem I had. My bad here - I should have clarified that this is my main question. I'll edit the question I posted as well. – Blawnode May 01 '20 at 18:29
  • Oh, also - Thanks a lot about the tip after the code! I had no idea, and I appreciate it a lot! – Blawnode May 01 '20 at 18:36