How do i make my script count once an animation on another script has finished?

Hey guys,

so, im continuing making a little quest tracking system. I want it so when a enemy wolf dies or when i click B the counter goes up. I’ve set it up in code, however it counts +1 for when the animation is present so it counts to 10 automatically.

Here’s the code for the quest tracker:

using UnityEngine;
using System.Collections;

public class Quest1tracker : MonoBehaviour {
	public AudioClip Questcompletesound;
	public Transform NPC;
	public Transform Wolf;

	
int counter = 0;
    int Maxcount = 10;
	
	
    void OnGUI(){

       GUI.Box( new Rect((Screen.width /2) +800,400,150,25), "Wolfs Killed " + counter + "/" + Maxcount);

       }

    void Update(){
		WolfHealth Eh = (WolfHealth)Wolf.GetComponent("WolfHealth");
		
       if (Input.GetKeyDown(KeyCode.B) || Eh.Deathanimation) {
			counter++;
       }
		
		if(counter == Maxcount) {
		audio.clip = Questcompletesound;
			audio.Play();
			
			NPC.GetComponent<Quest1Middle>().enabled = false;
			NPC.GetComponent<Quest1End>().enabled = true;
			GetComponent<Quest1Handintracker>().enabled = true;
			GetComponent<Quest1tracker>().enabled = false;
			
			
		}
		
		
       }
}

And this is the wolf health script(which contains death and death animation):

using UnityEngine;
using System.Collections;

public class WolfHealth : MonoBehaviour {
	public int MaxHealth = 320;
	public int CurHealth = 320;
	public int Death = 0;
	public GUIStyle Playercurhealthtext;
	public float HealthBarLength;
	public Transform Target;
	public GUIStyle Demonskin;
	public AnimationClip Deathanimation;
	
	
	void Start(){

		
		
	HealthBarLength = 200;	
		
	}
	
	void OnGUI () {
	
		float dist = Vector3.Distance(Target.position, transform.position);
		
		if( dist <15){
		
			GetComponent<EnemyAI>().enabled = true;
			 
		 GUI.Box(new Rect((Screen.width /2)+310,(Screen.height /2) +300,90,80),"", Demonskin);
		
			GUI.Box(new Rect((Screen.width /2) +110,(Screen.height /2) +300,200/(MaxHealth/CurHealth),20), CurHealth + "/" + MaxHealth, Playercurhealthtext);
		}
		if(dist > 20) {
			GetComponent<EnemyAI>().enabled = false;
			
		}
	}
	
		public void AdjustCurrentHealth(int Adj){
	
		CurHealth += Adj;
		
		if (CurHealth <0)
			CurHealth = 0;
		if(CurHealth > MaxHealth)
			CurHealth = MaxHealth;
		if(MaxHealth < 1)
			MaxHealth = 1;
		if(CurHealth == MaxHealth){
			animation.AddClip(Deathanimation, "Death");
			animation.Play();
			GetComponent<Deactivateparent>().enabled = true;
		    GetComponent<EnemyAI>().enabled = false;
			GetComponent<WolfHealth>().enabled = false;
		}	
		
		HealthBarLength = (200) * (CurHealth/(float)MaxHealth);
		
		
		
	
	}
	
	
	
	public void update() {
	
		 AdjustCurrentHealth(0);
	}
}

So how might i be able to get the counter to go up at the end of death animation. Also, can it be done so it counts 1 per death animation as I’d like to have multiple targets.

Many thanks in advance.

You can do something like this

    if(CurHealth == MaxHealth){
             KillWolf();
           } 

         *
         *
         *

private void KillWolf()
{
    animation.AddClip(Deathanimation, "Death");
    animation.Play();
    GetComponent<Deactivateparent>().enabled = true;
    GetComponent<EnemyAI>().enabled = false;
    GetComponent<WolfHealth>().enabled = false;
    
    Invoke("UpdateQuest",animation.clip.lenght );
}

private void UpdateQuest()
{
//call the update counter here

}

The UpdateQuest will called after the death animation.
You should create some static manager that contains the questtrackers and then update the quest tracker from there

Hope this was helpful