Re: Enabling script on seperate object on variable check
Posted: Wed Jul 31, 2024 3:14 am
On dialogue nodes, so using the script feature to set a variable to true or false etc on certain nodes.
Support and discussion forum for Pixel Crushers products
https://www.pixelcrushers.com:443/phpbb/
https://www.pixelcrushers.com:443/phpbb/viewtopic.php?t=8392
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);
}
}
}