Hi, I’m making a video game and I’m having trouble with the script for the first boss. I tried to make the boss not move until the script detects that the animation is playing, but I’m not really sure how. For some reason I get an error on line 41:
“error CS1061: ‘GameObject’ does not contain a definition for ‘animator’ and no accessible extension method ‘animator’ accepting a first argument of type ‘GameObject’ could be found (are you missing a using directive or an assembly reference?)”
The code is a mess, but it works except for that error, here it is:
.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.AI;
public class GigaChad : MonoBehaviour
{
private bool checkPlayer = false;
public Transform target;
public GameObject Boss;
public float CoolDown = 3.0f;
public bool CanAttack = true;
public int digit;
NavMeshAgent nav;
void Start()
{
Animator anim = Boss.GetComponent<Animator>();
nav = GetComponent<NavMeshAgent>();
}
void Update()
{
if (checkPlayer == true)
{
if (CanAttack == true)
{
digit = Random.Range(0, 101);
if (digit <= 80)
{
Punch();
digit = Random.Range(0, 101);
}
if (digit >= 81)
{
Combo();
digit = Random.Range(0, 101);
}
}
}
if (Boss.animator.GetCurrentAnimatorStateInfo(0).IsName("Punch"))
{
nav.SetDestination(target.position);
GetComponent<NavMeshAgent>().speed = 100f;
}
}
void OnTriggerEnter(Collider other)
{
if (other.tag == "player")
{
checkPlayer = true;
}
}
void Punch()
{
CanAttack = false;
Animator anim = Boss.GetComponent<Animator>();
anim.SetTrigger("IsAttack");
CanAttack = true;
GetComponent<NavMeshAgent>().speed = 0f;
}
void Combo()
{
CanAttack = false;
GetComponent<NavMeshAgent>().speed = 10f;
Animator anim = Boss.GetComponent<Animator>();
anim.SetTrigger("IsCombo");
nav.SetDestination(target.position);
GetComponent<NavMeshAgent>().speed = 100f;
CanAttack = true;
}
void Ultimate()
{
CanAttack = false;
GetComponent<NavMeshAgent>().speed = 100f;
Animator anim = Boss.GetComponent<Animator>();
anim.SetTrigger("IsUltimated");
StartCoroutine(ResetAttackCoolDown());
}
IEnumerator ResetAttackCoolDown()
{
yield return new WaitForSeconds(CoolDown);
CanAttack = true;
}
}
So if anyone knows how to fix that, I’d be grateful.
Also in the code, I’m not currently using the ResetAttackCoolDown and void Ultimate, so don’t look at that