So I’m attempting to set up my attacker so that the first defender it touches, it jumps over, then it enters a crawling animation and attacks everything it comes into contact afterwards normally. I’m having a little trouble figuring out the code though. Here’s what I’ve got so far
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Jackhammer : MonoBehaviour
{
Animator jhanimator;
private void OnTriggerEnter2D(Collider2D otherCollider)
{
GameObject otherObject = otherCollider.gameObject;
if (otherObject.GetComponent<Defender>() && jhanimator.GetCurrentAnimatorStateInfo(0).IsName("JHRun"))
{
GetComponent<Animator>().SetTrigger("jumpTrigger");
}
else if (otherObject.GetComponent<Defender>() && jhanimator.GetCurrentAnimatorStateInfo(0).IsName("JHCrawl"))
{
GetComponent<Attacker>().Attack(otherObject);
}
}
}
My plan was to run two if statements where it’ll look at what the attacker’s current animation state is when it bumps into a defender and either jump if it’s doing “JHrun” or attack if it’s doing “JHCrawl”. So far though, the only result is the jump won’t trigger and gives me a null reference exception error. Any help would be greatly appreciated!