I want to start the animation when destroying another game object. How is this possible? To have this in mind I was trying to use setActive() in the else statement where the object is destroyed. However, nothing happens, only it does activate when I put it inside if(target). So I'm trying something like this:
public void Update()
{
anim = GetComponent<Animator>();
anim.SetBool("isWalking", isWalking);
if (target)
{
bar.fillAmount = (float)health / baseHealth;
float distance = Vector3.Distance(transform.position, target.transform.position);
if (distance >= attackRange && isAttacking)
{
isWalking = true;
agent.SetDestination(target.transform.position);
}
if (distance - 1 <= attackRange)
{
isWalking = false;
agent.ResetPath();
}
if (distance - 1.5 <= attackRange && Random.value < Time.deltaTime && Time.time > lastAttackedAt + cooldown && agent.remainingDistance <= agent.stoppingDistance)
{
isAttacking = true;
isWalking = false;
Attack();
lastAttackedAt = Time.time;
anim.SetTrigger("isAttacking");
}
}
else
{
OnDeath();
spawnPortal.SetActive(true);
}
}
The object is well destroyed but still the animation does not appear. It remains hidden (unchecked)...