//======= Copyright (c) Stereolabs Corporation, All rights reserved. ===============
using UnityEngine;
///
/// Previously used in the ZED spatial mapping sample scene.
/// Spawns and destroys the bunnies.
///
public class EnemyBehavior : MonoBehaviour {
private const float lifeMax = 100;
public float life = lifeMax;
private SphereCollider capsuleCollider;
private bool isDying = false;
private void Start()
{
life = lifeMax;
capsuleCollider = GetComponent();
capsuleCollider.enabled = true;
isDying = false;
}
// Update is called once per frame
void Update () {
}
///
/// Set the dammage to an object
///
///
public void Dammage(float value)
{
if (!isDying)
{
life -= value;
if (life < 0)
{
Dead();
}
}
}
///
/// Disables the gameobject
///
public void StartSinking()
{
capsuleCollider.enabled = false;
Destroy(gameObject, 2.0f);
}
///
/// Play the animation of dead
///
private void Dead()
{
isDying = true;
GetComponent().enabled = false;
GetComponent().SetTrigger("Dead");
}
private void OnDestroy()
{
isDying = false;
}
}