Search Unity

Object struct of self

Discussion in 'Scripting' started by Richard_B, Jul 25, 2005.

  1. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    How can I get the Object class structure of the object the script is currently attached to? At the moment I have created a GameObject variable and assigned it to the same object in the object inspector, however, I would like skip this step.

    thanks,
    Richard.

    PS I am using this to destroy the object on a mouseDown event eg.

    Code (csharp):
    1.  
    2. var myself : GameObject;
    3. function OnMouseDown () {
    4.      Destroy (myself, 0.0);
    5. }
    6.  
     
  2. Jonathan Czeck

    Jonathan Czeck

    Joined:
    Mar 17, 2005
    Posts:
    1,713
    Destroy(gameObject, 0.0);

    A script inherits from MonoBehavior, and a MonoBehavior eventually inherits from Component, and a component is guaranteed to be attached to a gameObject.

    file:///Applications/Unity/Documentation/ScriptReference/Component.html#gameObject

    Cheers,
    -Jon
     
  3. Richard_B

    Richard_B

    Joined:
    Jul 22, 2005
    Posts:
    436
    Great - thanks.

    R.