Description
The Name
property of a GameObject
is a string that represents the name of the object. This name is primarily used for debugging purposes and for locating the object within a scene. It is a public, non-static property, meaning it can be accessed and modified from outside the class, and each instance of GameObject
can have its own unique name.
Usage
To get or set the name of a GameObject
, you can use the Name
property directly. This property is useful when you need to identify or differentiate between multiple game objects in a scene, especially during debugging or when searching for specific objects.
Example
// Example of setting and getting the Name property of a GameObject
// Create a new GameObject
GameObject myObject = new GameObject();
// Set the name of the GameObject
myObject.Name = "PlayerCharacter";
// Retrieve the name of the GameObject
string objectName = myObject.Name;
// Output the name
// Note: Avoid using Console.WriteLine in Sandbox, use appropriate logging or debugging tools instead
// Debug.Log(objectName);