Что ж, для простоты атакующая анимация (аниматор имеет параметр int, который управляет атакующей анимацией, когда он установлен на 4) не работает, даже если int меняется на 4.
Я использовал тот же код в другом объекте, и он отлично работает.
На скриншоте ниже показано управление аниматором и передача
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityStandardAssets.Characters.FirstPerson
{
[RequireComponent(typeof (CharacterController))]
public class BOSSATTACKS : MonoBehaviour {
public GameObject prefabProjectil;
private GameObject projectil;
public Vector3 offset;
public ParticleSystem tp;
public ParticleSystem fire;
public float timeBetweenFB = 20f;
public float timeBetweenAttacks = 10f;
public float timeBetweenTp = 30f;
public int attackDamage = 10;
public Animator anim;
public GameObject boss;
GameObject player;
PlayerHealth playerHealth;
bool playerInRange;
float timer;
void Awake ()
{
player = GameObject.FindGameObjectWithTag ("Player");
playerHealth = player.GetComponent <PlayerHealth> ();
}
void OnTriggerEnter (Collider other)
{
if(other.gameObject == player)
{
playerInRange = true;
}
}
void OnTriggerExit (Collider other)
{
if(other.gameObject == player)
{
playerInRange = false;
}
}
void Update ()
{
timer += Time.deltaTime;
if (timer >= timeBetweenAttacks && playerInRange)
{
StartCoroutine (Attack ());
}
if (timer >= timeBetweenTp && playerInRange == false)
{
StartCoroutine (tp1 ());
}
}
IEnumerator tp1()
{ timer = 0f;
anim.SetInteger ("atk", 2);
tp.Play ();
yield return new WaitForSeconds(2);
boss.transform.position = player.transform.position - offset;
anim.SetInteger ("atk", 3);
}
IEnumerator Attack ()
{
timer = 0f;
if (playerHealth.currentHealth > 0) {
anim.SetInteger ("atk", 4);
yield return new WaitForSeconds (2);
playerHealth.TakeDamage (attackDamage);
anim.SetInteger ("atk", 3);
}
}
}
}