Search Unity

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";