Скрипт работает правильно потому-что print с проверкой пишется но на всякий случай скрипт прикреплю:
using System.Collections;
using System.Collections.Generic;
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UIElements;
enum Mummies
{
Normal,
Thrower,
Kamikaze
}
public class Mummie : MonoBehaviour
{
public float speed, health, damage, size, atkSpeed, xpCount;
NavMeshAgent nma;
PlayerController player;
[SerializeField] Transform tntSpawnPoint;
[SerializeField] GameObject tntPref;
[SerializeField] Mummies type;
[SerializeField] string id;
// Start is called before the first frame update
void Start()
{
nma = GetComponent<NavMeshAgent>();
player = FindObjectOfType<PlayerController>();
nma.speed = speed;
gameObject.transform.localScale = new Vector3(size, size, size);
gameObject.GetComponent<BoxCollider>().enabled = true;
gameObject.GetComponent<Animator>().SetInteger("Type", type.GetHashCode());
id = id + Random.Range(0, 1000000).ToString();
}
// Update is called once per frame
void Update()
{
if (atkSpeed <= 0)
{
print($"Айди: {id}, Тип: {type}, atkSpeed: {atkSpeed} Иф на скорость атаки");
if (type.GetHashCode() == 0 || type.GetHashCode() == 2)
{
print($"Айди: {id}, Тип: {type}, atkSpeed: {atkSpeed} Иф на тип");
nma.SetDestination(player.transform.localPosition);
}
else if (type.GetHashCode() == 1)
{
print($"Айди: {id}, Тип: {type}, atkSpeed: {atkSpeed} Иф на тип");
tntSpawnPoint.LookAt(player.transform.localPosition);
if (Vector3.Distance(transform.position, player.transform.position) >= 20)
{
nma.SetDestination(player.transform.localPosition);
gameObject.GetComponent<Animator>().SetBool("Staying", false);
}
else
{
nma.ResetPath();
transform.LookAt(player.transform.localPosition);
gameObject.GetComponent<Animator>().SetBool("Staying", true);
}
}
}
if (health <= 0)
{
Destroy(gameObject);
FindObjectOfType<GameManager>().enemyCount--;
FindObjectOfType<PlayerController>().countForDamage--;
FindObjectOfType<GameManager>().xp += xpCount;
FindObjectOfType<GameManager>().chanceTop += xpCount;
FindObjectOfType<GameManager>().chanceDown -= xpCount;
}
atkSpeed -= Time.deltaTime;
}
private void OnTriggerStay(Collider collision)
{
if (collision.gameObject.CompareTag("Player") && atkSpeed <= 0)
{
gameObject.GetComponent<BoxCollider>().enabled = false;
gameObject.GetComponent<Animator>().SetTrigger("Damaging");
}
}
void DamageToPlayer()
{
gameObject.GetComponent<BoxCollider>().enabled = true;
player.health -= damage;
atkSpeed = 2;
FindObjectOfType<GameManager>().chanceTop -= damage;
FindObjectOfType<GameManager>().chanceDown += damage;
}
void SpawnTNT()
{
GameObject newTnt = Instantiate(tntPref, tntSpawnPoint.position, tntSpawnPoint.rotation);
}
void DestroyMe()
{
Destroy(gameObject);
}
}
Все анимации работают, объекты по которым должны ходить мумии статичны, навигация запечена, а скорость не равна нулю так как в начале скрипта она задается изначальным настройкам.
Но единственный тип который работает это Kamikaze.