Hey,
So I have an enemy that Im testing with and I instantiate 2 of them. They are both the same game object so they have the same animations and stuff.
So I coded the enemy animation to play when hit is detected from player:
Enemy Animation.js
var minRunSpeed = 1.0;
private var enemy: Transform;
function Start(){
enemy = GameObject.FindWithTag ("Player").transform;
animation.wrapMode = WrapMode.Loop;
animation["attack"].wrapMode = WrapMode.Once;
animation["damage"].wrapMode = WrapMode.Once;
animation["idle"].layer = -1;
animation["walk"].layer = -1;
animation["damage"].layer = 1;
animation.Stop();
}
function Update(){
var controller : EnemyControls = GetComponent(EnemyControls);
for (var state : AnimationState in animation) {
state.speed = 1.5;
if (controller.eMoving == true){
animation.CrossFade ("walk");
} else{
animation.CrossFade ("idle");
}
var Hit: PlayerControls = GetComponent(PlayerControls);
var weapOn : WeaponHit = GetComponent (WeaponHit);
if (Hit.eHit == true){
animation.Play ("damage");
transform.LookAt(enemy);
//transform.Translate(Vector3.forward * -.15 * Time.deltaTime);
if (animation["damage"].time >= .2){
Hit.eHit = false;
weapOn.weapHit = false;
//Debug.Log (transform.position);
}
}
}
}
The eHit variable is what is sent and checked after hit is detected from the WeaponHit.js:
static var weapHit: boolean;
function OnTriggerEnter(hit: Collider){
if(hit.gameObject.tag == "Enemy"){
weapHit = true;
}
}
and checked in the PlayerControls.js
var weapOn : WeaponHit = GetComponent (WeaponHit);
if (weapOn.weapHit == true){
if (animation["att1"].time >= .4 animation["att1"].time < .6){
print ("player hit");
eHit = true;
Debug.Log(eHit);
if (eHit == false){
weapOn.weapHit = false;
}
}
if (animation["att2"].time >= .3 animation["att2"].time < .7){
print ("player hit");
eHit = true;
Debug.Log(eHit);
if (eHit == false){
weapOn.weapHit = false;
}
}
if (animation["att3"].time >= .8 animation["att3"].time < 1.04){
print ("player hit");
eHit = true;
Debug.Log(eHit);
if (eHit == false){
weapOn.weapHit = false;
}
[b]eHit = false[/b];
}
What basically happens though is that the enemies will play the damage animation if one of them is hit, which is not ideal or what I want. Any work arounds?