Цитата allods (
)
Attack у вас не loop случаем
в том то и дело, что нет. я даже в скрипте явно указал, что WrapMode.OnceДобавлено (07.08.2014, 01:35)
---------------------------------------------
В общем решил эту проблему через зад )
Код
using UnityEngine;
using System.Collections;
public class EnemyAttack : MonoBehaviour {
public float Radius;
public float AttackSpeed;
public int Damage;
public AnimationClip Attack;
public AnimationClip AttackStand;
[SerializeField]
bool attack;
GameObject player;
Transform localTransform;
float attackTimer; //вспомогательная переменная
GeneralPlayer playerGeneral;
Vector3 targetAngel = new Vector3();
/// attack
/// attackStand
///
///
void Awake()
{
localTransform = transform;
player = GameObject.FindGameObjectWithTag(ManagerTag.PLAYER);
playerGeneral = GameObject.FindGameObjectWithTag(ManagerTag.PLAYER).GetComponent<GeneralPlayer>();
Attack.wrapMode = WrapMode.Once;
//добавляем анимации
}
// Update is called once per frame
void Update()
{
attackCondition();
//таймер
if (attackTimer > 0) attackTimer -= Time.deltaTime;
if (attackTimer < 0) attackTimer = 0;
begiAttack();
print(attackTimer);
}
void attackCondition()
{
if (EnemyAI._CanAttack && !EnemyAI._Died)
{
attack = true;
}
else
{
attack = false;
}
}
/// Атака и условия для нанесения урона
void begiAttack()
{
if (attack && attackTimer == 0)
{
//атакуем
print("атакуем");
animation.CrossFade(Attack.name);
if (!IsInvoking("animStand"))
Invoke("animStand", Attack.length);
targetAngel = player.transform.position - localTransform.position;//
float direction = Vector3.Angle(targetAngel, localTransform.forward);
if (direction <= Radius)
{
takeDamage();
print("damage angel");
}
attackTimer = AttackSpeed;//приравниваем таймер к скорости атаки
}
}
void animStand()
{
animation.CrossFade(AttackStand.name);
}
/// нанесение урона
void takeDamage()
{
if (playerGeneral != null)
{
playerGeneral.CurHp -= Damage;
}
else
{
return;
}
}
}