- Home /
Kill Quest Issue
Hi guys I am trying to make Kill quest system for my game but unfortunately I cant manage to pass this point I am following this tutorial but still doesnt work. https://www.youtube.com/watch?v=LONrh-6xbXQ
Here are the scripts
[System.Serializable] public class Quest { public bool isActive; public List Goals = new List(); public string title; public string description; public int experienceReward; public int goldReward; //public Item ItemReward {get; set;} public bool Completed { get; set; }
public void CheckGoals()
{
Completed = Goals.All(g => g.Completed);
if (Completed) GiveReward();
}
public void Complete()
{
isActive = false;
Debug.Log(title + "was completed");
}
void GiveReward()
{
// give reward
Debug.Log("Reward given");
}
}
[System.Serializable] public class Goal { public string Description; public bool Completed; public int CurrentAmount; public int RequiredAmount;
public virtual void Init()
{
//default
Debug.Log("init works");
}
public void Evaluate()
{
if(CurrentAmount >= RequiredAmount)
{
Complete();
Debug.Log("quest completed");
}
}
public void Complete()
{
Completed = true;
}
}
public class KillGoal : Goal { public int EnemyID; public int QuestAmount; public KillGoal(int enemyID, string description, bool completed, int currentAmount, int requiredAmount) { this.EnemyID = enemyID; this.Description = description; this.Completed = completed; this.CurrentAmount = currentAmount; this.RequiredAmount = requiredAmount; }
public override void Init()
{
base.Init();
CombatEvents.OnEnemyDeath += this.EnemyDied;
Debug.Log("initiliasing");
}
void EnemyDied(IEnemy enemy)
{
if(enemy.ID == EnemyID)
{
this.CurrentAmount++;
Evaluate();
Debug.Log("enemyDied ++");
}
}
}
public class CombatEvents : MonoBehaviour { public delegate void EnemyEventHandler(IEnemy enemy); public static event EnemyEventHandler OnEnemyDeath;
public static void EnemyDied(IEnemy enemy)
{
if(OnEnemyDeath != null)
{
OnEnemyDeath(enemy);
}
}
}
public class EnemyHealth : MonoBehaviour ,IEnemy { public int enemyHealth; public int currentHealth; public int speed; public delegate void onEnemyDeath(); public static event onEnemyDeath enemyDeath;
public int ID { get; set; }
// public int enemyQScore = 1;
public LayerMask Ground;
private Animator anim;
public GameObject bloodEffect;
// public GameObject bloodSplash; public int scoreValue = 1; public GameAssets Player;
void Start()
{
ID = 1;
anim = GetComponent<Animator>();
currentHealth = enemyHealth;
}
void Update()
{
if (enemyHealth <= 0)
{
//Instantiate(bloodSplash, transform.position, Quaternion.identity);
Instantiate(bloodEffect, transform.position, Quaternion.identity);
UpdateQuestScore();
Destroy(gameObject);
SoundManager.PlaySound(SoundManager.Sound.EnemyDie);
}
{
transform.Translate(Vector2.left * speed * Time.deltaTime);
}
}
public void TakeDamage(int damage)
{
Instantiate(bloodEffect, transform.position, Quaternion.identity);
enemyHealth -= damage;
// Debug.Log("damage TAKEN !");
}
public void OnDestroy()
{
ScoreManager.score += scoreValue;
}
public void UpdateQuestScore()
{
if (enemyDeath != null)
{
enemyDeath();
Debug.Log("updateQS");
}
}
}
Will appreciate any help or advice. I cant update the score after my enemy dies to the quest so i can reach the required amount and finish the quest.
Your answer
Follow this Question
Related Questions
Attaching kill volume to a particle effect..posible and how? 3 Answers
I want to know how to script a kill counter 2 Answers
Kill Streak Help 3 Answers
How can I have the player be able to kill an enemy by jumping on top of it? 1 Answer
Scoring help ! 1 Answer