Enabling script on seperate object on variable check
Re: Enabling script on seperate object on variable check
On dialogue nodes, so using the script feature to set a variable to true or false etc on certain nodes.
Re: Enabling script on seperate object on variable check
Hi,
That should work. Make sure OnEnable and OnDisable are really being called at the correct times at runtime. Feel free to send a reproduction project to tony (at) pixelcrushers.com if it still isn't working.
Alternatively, you could write a C# method to turn the outline on or off. Then register that method with Lua and use it directly in the dialogue entry's Script field. This way you don't have to deal with bools at all.
That should work. Make sure OnEnable and OnDisable are really being called at the correct times at runtime. Feel free to send a reproduction project to tony (at) pixelcrushers.com if it still isn't working.
Alternatively, you could write a C# method to turn the outline on or off. Then register that method with Lua and use it directly in the dialogue entry's Script field. This way you don't have to deal with bools at all.
Re: Enabling script on seperate object on variable check
Hi Tony, brilliant thank you, I almost have it perfect now by registering a function. So now I can enable and disable the outline on a dialogue node, but unfortuantely can only get that working on the item the dialogue is taking place on. So say I wanted to have a dialogue option trigger if it can be outlined on a seperate object I can't figure that out.
Apologies for this and thank you again.
EDIT: Apologies, in fact this isn't working at all it would seem. And i'm only making matters worse apologies. I will try again in the evening. Thank you again
Apologies for this and thank you again.
Code: Select all
using PixelCrushers.DialogueSystem;
using System.Collections.Generic;
using UnityEngine;
public class EnableOutline : MonoBehaviour
{
Outline outline;
public bool showOutline = true;
private void Awake()
{
if (!TryGetComponent(out outline)) return;
outline.enabled = false;
}
void OnEnable()
{
Lua.RegisterFunction(nameof(CanOutline), this, SymbolExtensions.GetMethodInfo(() => CanOutline(false)));
}
void OnDisable()
{
// Note: If this script is on your Dialogue Manager & the Dialogue Manager is configured
// as Don't Destroy On Load (on by default), don't unregister Lua functions.
Lua.UnregisterFunction(nameof(CanOutline)); // <-- Only if not on Dialogue Manager.
}
public bool CanOutline(bool canOutline)
{
if(canOutline == true)
{
showOutline = true;
return true;
}
else
{
showOutline = false;
return false;
}
}
void Update()
{
if (!outline) return;
if(CanOutline(showOutline))
{
outline.enabled = Input.GetKey(KeyCode.Tab);
}
}
}
Re: Enabling script on seperate object on variable check
Hi,
Lua.RegisterFunction() registers the function globally. You can't have a separate CanOutline() method on more than one GameObject. You could specify the GameObject by name as a parameter to the function.
However, you may find it easiest to use an OnExecute() scene event:
Lua.RegisterFunction() registers the function globally. You can't have a separate CanOutline() method on more than one GameObject. You could specify the GameObject by name as a parameter to the function.
However, you may find it easiest to use an OnExecute() scene event:
Re: Enabling script on seperate object on variable check
Hi Tony,
Thank you so very much, that works perfetly using Scene Events and is very easy to set up. Thank you again for your time and your help, it's greatly appreciated.
Thank you so very much, that works perfetly using Scene Events and is very easy to set up. Thank you again for your time and your help, it's greatly appreciated.
Re: Enabling script on seperate object on variable check
Glad to help!