Hi,
In my game, enemies aren't destroyed or disabled on death. They lie there until the player moves into another scene. How can I trigger a counter for killing enemies if I'm not using destroy or disable for defeating enemies?
Trigger on Death [SOLVED]
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
Trigger on Death [SOLVED]
Last edited by mschoenhals on Sun Dec 22, 2019 6:51 pm, edited 1 time in total.
Re: Trigger on Death
Hi,
There are still several ways you can increment a counter. One of the easiest is to send a message using Quest Machine's message system.
1. Add a counter to your quest (e.g., "orcsKilled"). Set Value Mode to Messages. Add a message such as "Killed" + "Orc".
2. Optionally add some HUD text that shows the counter value, such as "{#orcsKilled}/{>#orcsKilled}". You can use the Quest Reference window to copy these counter tags to the clipboard so you don't have to type them manually.
3. Add a QuestControl component to your enemy. If your enemy has a UnityEvent that's invoked when it's killed, such as OnDeath(), configure this event to call QuestControl.SendToQuestMachine with the message that increments the counter, such as "Killed:Orc".
4. If you don't have a UnityEvent, you can skip #3. Instead, call MessageSystem.SendMessage() in code:
There are still several ways you can increment a counter. One of the easiest is to send a message using Quest Machine's message system.
1. Add a counter to your quest (e.g., "orcsKilled"). Set Value Mode to Messages. Add a message such as "Killed" + "Orc".
2. Optionally add some HUD text that shows the counter value, such as "{#orcsKilled}/{>#orcsKilled}". You can use the Quest Reference window to copy these counter tags to the clipboard so you don't have to type them manually.
3. Add a QuestControl component to your enemy. If your enemy has a UnityEvent that's invoked when it's killed, such as OnDeath(), configure this event to call QuestControl.SendToQuestMachine with the message that increments the counter, such as "Killed:Orc".
4. If you don't have a UnityEvent, you can skip #3. Instead, call MessageSystem.SendMessage() in code:
Code: Select all
PixelCrushers.MessageSystem.SendMessage(this, "Killed", "Orc");
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
Re: Trigger on Death
So in steps 3 and 4, is this hard coded in? Is there a way to do it where I wouldn't have to change the code every time I want to have a quest that involves killing a particular type of enemy?
Re: Trigger on Death
It doesn't have to be hard-coded. If you have script that identifies the enemy type, you can pass that instead. Something like:
or even pass the GameObject name if that identifies the enemy type.
If you're using Quest Machine's procedural quest generation, you can define an EntityType asset, add a QuestEntity component to the enemy, and assign the EntityType asset to it. Then you can send the entity type:
Code: Select all
PixelCrushers.MessageSystem.SendMessage(this, "Killed", GetComponent<Enemy>().EnemyName);
If you're using Quest Machine's procedural quest generation, you can define an EntityType asset, add a QuestEntity component to the enemy, and assign the EntityType asset to it. Then you can send the entity type:
Code: Select all
PixelCrushers.MessageSystem.SendMessage(this, "Killed", GetComponent<QuestEntity>().entityType.name);
-
- Posts: 118
- Joined: Thu Dec 19, 2019 7:38 am
Re: Trigger on Death
Got it!
Turns out that I do have an On Die() event that I could use to track the kill count. I added the Quest Control and added it to the Event and it worked perfectly!
Thanks for your help,
Mike
Turns out that I do have an On Die() event that I could use to track the kill count. I added the Quest Control and added it to the Event and it worked perfectly!
Thanks for your help,
Mike
Re: Trigger on Death [SOLVED]
Glad to help!