Object.name

Unity · Версия 2020.3 LTS · Scripting · Object

Object.name

public string name;

Описание

Имя объекта.

Компоненты имеют то же имя, что и игровой объект и все присоединенные компоненты. Если класс является производным от MonoBehaviour, он наследует поле «имя» от MonoBehaviour. Если этот класс также присоединен к GameObject, то в поле «name» указывается имя этого GameObject.

using UnityEngine;
using System.Collections;

public class ExampleClass : MonoBehaviour
{
    public GameObject exampleOne;
    public GameObject exampleTwo;
    public GameObject exampleThree;

    void Start()
    {
        //Sets the name of GameObject One.
        exampleOne.name = "Ben";
        //Sets the name of GameObject Two.
        exampleTwo.name = "Ryan";
        //Sets the name of GameObject Three.
        exampleThree.name = "Oscar";

        // Отображает их имена в консоли.
        Debug.Log("The names of these three objects are " + exampleOne.name + exampleTwo.name + exampleThree.name);
    }
}

Обновлено 17 ноября 2026 г.