Call custom method in Dialogue System
Posted: Thu May 25, 2023 1:54 pm
Hello everyone,
I am currently working on a Pokémon game in Unity and I am encountering some difficulties with the Dialogue System plugin. I was wondering if anyone could offer some guidance and support on this matter.
Let me provide some context. My game consists of a main scene and several additional scenes that are asynchronously loaded based on the player's movements within the map. The player character is present in the main scene, while the non-player characters (NPCs) are scattered throughout the various scenes.
Specifically, I have NPCs with scripts that are designed to give a Pokémon to the player character. I would like to incorporate this interaction into the Dialogue System conversations. I have attempted to modify my script and applied the changes within the Unity editor, but the process has proven to be quite complex, and unfortunately, it is not functioning as intended.
To provide further assistance, I have attached my script and screenshots of the settings I have adjusted within the editor.
Any help, advice, or suggestions on how I could properly implement this functionality would be greatly appreciated. Thank you in advance for your support.
Nicolò
I am currently working on a Pokémon game in Unity and I am encountering some difficulties with the Dialogue System plugin. I was wondering if anyone could offer some guidance and support on this matter.
Let me provide some context. My game consists of a main scene and several additional scenes that are asynchronously loaded based on the player's movements within the map. The player character is present in the main scene, while the non-player characters (NPCs) are scattered throughout the various scenes.
Specifically, I have NPCs with scripts that are designed to give a Pokémon to the player character. I would like to incorporate this interaction into the Dialogue System conversations. I have attempted to modify my script and applied the changes within the Unity editor, but the process has proven to be quite complex, and unfortunately, it is not functioning as intended.
To provide further assistance, I have attached my script and screenshots of the settings I have adjusted within the editor.
Any help, advice, or suggestions on how I could properly implement this functionality would be greatly appreciated. Thank you in advance for your support.
Code: Select all
public class PokemonGiver : MonoBehaviour
{
[Tooltip("Typically leave unticked so temporary Dialogue Managers don't unregister your functions.")]
public bool unregisterOnDisable = false;
[SerializeField] Pokemon pokemonToGive;
[SerializeField] public string uniqueID;
bool used = false;
void OnEnable()
{
Lua.RegisterFunction(nameof(GivePokemon), this, SymbolExtensions.GetMethodInfo(() => GivePokemon((PlayerController)null)));
Lua.RegisterFunction(nameof(CanBeGiven), this, SymbolExtensions.GetMethodInfo(() => CanBeGiven()));
}
void OnDisable()
{
if (unregisterOnDisable)
{
Lua.UnregisterFunction(nameof(GivePokemon));
Lua.UnregisterFunction(nameof(CanBeGiven));
}
}
public IEnumerator GivePokemon(PlayerController player)
{
pokemonToGive.Init();
player.GetComponent<PokemonParty>().AddPokemon(pokemonToGive);
used = true;
AudioManager.i.PlaySfx(AudioId.PokemonObtained, pauseMusic: true);
yield return null;
}
public bool CanBeGiven()
{
return pokemonToGive != null && !used;
}
}