using UnityEngine; using System; using System.Reflection; public static class UniqueIDGenerator { public static string GenerateUniqueID(MonoBehaviour script) { Type scriptType = script.GetType(); string uniqueID = $"{scriptType.Name}_{Guid.NewGuid().ToString()}"; // Set the value of the uniqueID field using reflection FieldInfo uniqueIDField = scriptType.GetField("uniqueID"); if (uniqueIDField != null) { uniqueIDField.SetValue(script, uniqueID); Debug.Log($"Generated Unique ID: {uniqueID}"); return uniqueID; } else { Debug.LogError($"The script {scriptType.Name} does not have a 'uniqueID' field."); return null; } } }