- Home /
Error : Animator has not been initialized. UnityEngine.Animator:SetBool(String, Boolean)
I notice my animation on my enemy ai wasn't working . It only idles . I look at the console and I saw this error : Animator has not been initialized.
UnityEngine.Animator:SetBool(String, Boolean)
Enemyai:Update() (at Assets/Enemyai.cs:40)
I need to change something on line 40 . I used this same script on a another enemy ai . Here is my script :
using UnityEngine;
using System.Collections;
public class Enemyai : MonoBehaviour {
public Transform player;
static Animator anim;
void Start ()
{
anim = GetComponent<Animator> ();
}
void Update ()
{
if (Vector3.Distance(player.position, this.transform.position) < 10)
{
Vector3 direction = player.position - this.transform.position;
direction.y = 0;
this.transform.rotation = Quaternion.Slerp (this.transform.rotation,Quaternion.LookRotation(direction), 0.1f);
anim.SetBool("isIdle",false);
if(direction.magnitude > 2.6 )
{
this.transform.Translate(0,0,0.05f);
anim.SetBool("isMoving",true);
anim.SetBool("isAttacking",false);
}
else
{
anim.SetBool("isAttacking",true);
anim.SetBool("isMoving",false);
}
}
else
{
anim.SetBool("isIdle",true);
anim.SetBool("isMoving",false);
anim.SetBool("isAttacking",false);
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Set All bool parameters in animator to false 1 Answer
How to schedule responses (based on player's input text) for text adventure game? 0 Answers
Animtor Stuck 1 Answer
Double collision on "ground" tagged object results in player thinking they're in air? 1 Answer
Set a Bool Through Function 1 Answer