Untitled
unknown
csharp
2 years ago
1.7 kB
9
Indexable
using BepInEx;
using BepInEx.Logging;
using UnityEngine;
namespace UItest
{
[BepInPlugin(PluginInfo.PLUGIN_GUID, PluginInfo.PLUGIN_NAME, PluginInfo.PLUGIN_VERSION)]
public class Plugin : BaseUnityPlugin
{
GameObject Darkness;
private void Awake()
{
// Plugin startup logic
Logger.LogInfo($"Plugin {PluginInfo.PLUGIN_GUID} is loaded!");
}
public GameObject GetCorrectBackground()
{
GameObject[] backgroundObjects = GameObject.FindObjectsOfType<GameObject>(); //find ALL gameobjects in the scene
for (int i = 0; i < backgroundObjects.Length; i++) //loop through all objects we found
{
if (backgroundObjects[i].name == "Background") // Check if the object is named 'Background'
{
Transform parent = backgroundObjects[i].transform.parent; // get it's parent object
if (parent != null && parent.name == "SafeArea") // Check if the parent is named 'SafeArea'
{
return backgroundObjects[i]; //if we made it here, it passed our check! it returns the correct background
}
}
}
// If we make it here, then no object named 'Background' with a parent named 'SafeArea' was found, so we return 'null'
return null;
}
private void Update()
{
if (!Darkness)
{
Darkness = GetCorrectBackground();
Debug.Log("setting darkness");
}
else
{
Darkness.SetActive(false);
Debug.Log("disabling darkness");
}
}
}
}
Editor is loading...
Leave a Comment