I am using the Unity tutorials to make a project. When I go to build the game, I get two errors both from the same script telling me "The Name 'GUID' does not exist in the current context", and it is really frustrating. This is not anything that the standard assets were able to fix when I tried, but I just need help. Thank you, everyone! As well as this, the script it was in is really messy and all in one line. I'm not sure how that happened I didn't do that.
using System;
using UnityEditor;
using UnityEngine;
using System.Linq;
[ExecuteInEditMode]
[DisallowMultipleComponent]
[AddComponentMenu("")]
public class SceneObjectGUIDComponent : MonoBehaviour
{
[SerializeField] private string m_Id;
[NonSerialized] private bool m_Registered;
public string id
{
get { return m_Id; }
}
public void Awake()
{
if (!Application.isEditor)
Destroy(this);
if (string.IsNullOrEmpty(m_Id))
{
m_Id = GUID.Generate().ToString();
}
else
{
var components = UnityEngine.Object.FindObjectsOfType();
if (components.Any(c => c.m_Id == m_Id && c != this))
{
m_Id = GUID.Generate().ToString();
}
}
hideFlags |= HideFlags.HideInInspector;
Register();
}
private void Register()
{
if (m_Registered || !Application.isEditor)
return;
SceneObjectGUIDManager.instance.Register(this);
m_Registered = true;
}
void OnValidate()
{
// Register in OnValidate becuase Awake in not called on domain reload in edit mode
Register();
}
void OnDestroy()
{
if (SceneObjectGUIDManager.IsInitiated)
SceneObjectGUIDManager.instance.Deregister(this);
}
}
↧