Alright so as the title suggests, I’m trying to discover a way to anger a group of guards through dialogue (Quests & Dialogues course, Lecture 51), but the unique point here is that I have a Respawn Manager attached to the guards (so they can die and come back to life after their death). As far as we have reached, this was Brians’ suggestion:
You'll need a way to add them to the Aggro Group....
You can add methods to the AggroGroup to add and remove members.
Then in Respawn Manager, add a SerializedField for the AggroGroup
When the character is created, if there is an AggroGroup add it to the AggroGroup
When the character dies, if there is an AggroGroup, remove it from the AggroGroup.
The DialogueTrigger, on the other hand has the problem that it can't link to an AggroGroup (because a Prefab can't link to a scene object). So we're going to have to trick things out a bit.
You'll need a MonoBehavior that has two methods:
SetAggroGroup - The Respawn Manager will do this if it finds this MonoBehaviour on the character, it should take in an AggroGroup and store that value in a variable.
CallAggroGroup - This is the method you will link in the DialogueTrigger. It will check to make sure the Aggrogroup isn't null, and then call the appropriate method.
I gave his suggestion a go, and this is how it ended up before I got stuck:
RespawnManager.Respawn():
// TEST: Delete if failed
if (aggroGroup != null) {
dialogueAggro.SetAggroGroup();
aggroGroup.AddFighter(spawnedEnemy.GetComponent<Fighter>());
}
RespawnManager.OnDeath():
// TEST: Delete if failed
if (aggroGroup != null) {
aggroGroup.RemoveFighter(spawnedEnemy.GetComponent<Fighter>());
}
AggroGroup.cs Add and Remove Method:
public void AddFighter(Fighter fighter) {
fighters.Add(fighter);
}
public void RemoveFighter(Fighter fighter) {
fighters.Remove(fighter);
}
DialogueAggro.cs (a new script I created to host the ‘SetAggroGroup()’ and ‘CallAggroGroup()’ functions (also the most confusing one to figure out):
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using RPG.Combat;
namespace RPG.Respawnables {
public class DialogueAggro : MonoBehaviour
{
[SerializeField] AggroGroup aggroGroup;
public void CallAggroGroup() {
if (aggroGroup != null) SetAggroGroup();
}
public void SetAggroGroup(AggroGroup aggroGroup2) {
aggroGroup2 = aggroGroup;
}
}
}
DialogueTrigger.cs:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
using RPG.Respawnables;
using RPG.Combat;
namespace RPG.Dialogue {
public class DialogueTrigger : MonoBehaviour
{
[SerializeField] string action;
[SerializeField] UnityEvent onTrigger;
// TEST: Delete if failed
[SerializeField] AggroGroup aggroGroup;
public void Trigger(string actionToTrigger) {
if (actionToTrigger == action) {
// TEST: Delete if failed:
if (aggroGroup != null) DialogueAggro.CallAggroGroup();
onTrigger.Invoke();
// if the action we want to activate is equal to our 'actionToTrigger',
// we will launch that action (using 'Invoke()')
}
}
}
}
Needless to say, this did not work as expected (Mainly because I didn’t fully understand how to code it…). What fixes can be done here?
Here’s the link to the original conversation, if it helps in anyway: https://www.udemy.com/course/unity-dialogue-quests/learn/lecture/22861315#questions/20490710/