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);
}
}
}
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);
}
}
}