Die don't play death animation??

Hrohibil

Member
Hello


Pleaese see below code.

I added a health component on a AI robot.
Added this script to it.

When i shoot and hit him i do see in the inspector that the health goes down, but after it reaches zero he should play the die animation, instead he keeps wandering around.

I suspect its because i use BD to control him, so he is in wander state.. I thought the script would override BD?
So how do i connect those two, so when health goes down he dies and plays the animation as per below script..



using System.Collections;
using System.Collections.Generic;
using UnityEngine;



namespace BehaviorDesigner.Runtime.Tactical
{


public class dieROBO : MonoBehaviour, IDamageable
{


// The amount of health to begin with
public float startHealth = 100;

public float currentHealth;

Animator anim;

/// <summary>
/// Initailzies the current health.
/// </summary>
private void Awake()
{
currentHealth = startHealth;
anim = GetComponent<Animator>();
}

/// <summary>
/// Take damage. Deactivate if the amount of remaining health is 0.
/// </summary>
/// <param name="amount"></param>
public void Damage(float amount)
{
currentHealth = Mathf.Max(currentHealth - amount, 0);

if (currentHealth == 0)
{
gameObject.SetActive(false);
anim.Play("DeathFrontArmed");
Debug.Log("ROBO IS DEAD");


}
}

// Is the object alive?
public bool IsAlive()
{
return currentHealth > 0;
}


public void ResetHealth()
{
currentHealth = startHealth;
gameObject.SetActive(true);
}

}

}
 
This isn't related to the character controller so I am moving the thread location.

Behavior Designer doesn't do anything with the animator so it's up to your animator structure/script. Due to my support load I am not able to debug custom scripts but I recommend stepping through your damage method to see if it is triggering the animation.
 
Ok thank you Justin.
I added a new script called "PlayerDie" and used UCC events to grab the die function from there, it works..
 
Top