Hello, I am trying to make a boss states… In boss animator, I created Idle to walk animation connection. On my idle animation(in animator), I attached Behaviour script in which I want to get variable from a boss health script(animator and scripts are on the same object). So that when boss health is for example <= 50 he starts walking aka animator.SetBool(“isFollowing”, true); which will make him transfer from idle to follow behaviour which is coded to follow me…
How can I reference his health value in his behaviour script if they are on his- same- object.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class IdleBehaviour : StateMachineBehaviour
{
//reference health value from EnemyHealth script
void Start()
{
//HHealth = GameObject.Find("Hiram").GetComponent<EnemyHealth>();
}
override public void OnStateEnter(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
override public void OnStateUpdate(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
// if his health is lower than 50, isFollowing bool is true
}
// OnStateExit is called when a transition ends and the state machine finishes evaluating this state
override public void OnStateExit(Animator animator, AnimatorStateInfo stateInfo, int layerIndex)
{
}
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class EnemyHealth : MonoBehaviour
{
public int currentHealth;
public float damage = 10;
public void TakeDamage(int damage)
{
currentHealth -= damage;
//animacija primljenog udarca
if(currentHealth <= 0)
{
Die();
}
}
}