Answer the question
In order to leave comments, you need to log in
Why does my script give an error on SetBool?
In my script for the animation of the enemy, it gives an error! The script does not see the SetBool type, although I did everything right! I will give a script and a screen!
using System.Collections;
using UnityEngine;
using UnityEngine.AI;
public class EnemyController : MonoBehaviour
{
public NavMeshAgent agent;
public Animation animator;
private Transform player;
private bool attack;
private void Start()
{
player = GameObject.FindGameObjectWithTag("Player").transform;
StartCoroutine(findPath());
}
IEnumerator playerDetect()
{
while (true)
{
if (player == null)
break;
if (Vector3.Distance (transform.position, player.position) < 1f)
{
animator.SetBool("attack", true);
player.SendMessage("damege");
}
yield return new WaitForSeconds (.3f);
}
}
IEnumerator findPath()
{
while (true)
{
if (player != null)
{
agent.SetDestination(player.position);
yield return new WaitForSeconds(2f);
}
else break;
}
}
private void Update()
{
}
}
Answer the question
In order to leave comments, you need to log in
The code is not working, it's obvious you don't understand what you're doing. You have a public Animation animator; although it should be public Animator animator; if you want to reference the Animator component. Moreover, this same component must be received in Start and only after that call animator.SetBool("attack", true)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question