Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Help With Accessing A Name Component

Discussion in 'Scripting' started by DkuCook, Sep 2, 2014.

  1. DkuCook

    DkuCook

    Joined:
    Aug 29, 2014
    Posts:
    10
    Hey guys just a quick one.

    How do I make a script assign the name of the object it is attached to to a variant.
    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3.  
    4. public class BuildingAssembler : MonoBehaviour {
    5.  
    6.     public GameObject TargetGameObject;
    7.  
    8.     void Start ()
    9.     {
    10.         TargetGameObject = //What Would I Put Here??\\);
    11.     }
    12. }
    13.  
    I need to to be unique to a number of objects so I can't just enter the Game Objects Name.
    Any help would be great.
    Thanks Guys.
     
  2. KelsoMRK

    KelsoMRK

    Joined:
    Jul 18, 2010
    Posts:
    5,539
  3. JonyderKiller

    JonyderKiller

    Joined:
    Sep 1, 2012
    Posts:
    10
    You can simple say:
    Code (CSharp):
    1. gameObject.name = "Your name";