- Home /
How to refer to the class itself?
I am still very new to Unity and am trying to learn. I found out about iTween and thought it is similar to the Flash version of it. In a Javascript file called `MyCube.js` attached to a cube in the scene, I had a this line in the `OnSelected` function:
iTween.MoveTo(this, {"z": -1, "time": 0.5});
From the iTween documentation, the first argument takes in a `GameObject`. Since all objects in the scene inherits from the `GameObject` and I want it to refer to itself, I thought I write "`this`" to represent the MyCube.
However, I get an error saying that:
BCE0023: No appropriate version of 'iTween.MoveTo' for the argument list '(MyCube, Boo.Lang.Hash)' was found.
How can I refer to a class itself in Unity?
Answer by OperationDogBird · Sep 01, 2012 at 07:11 AM
'this' refers to the script and not the gameObject. You can simply say
gameObject
to refer to the gameObject that this script is attached to. It is the same as saying
this.gameObject
thanks! but this brings up another question: if "`this`" refers to the script itself but the script isn't a `gameObject`, then what is the type of the script itself?
@xEnOnn The type of the script will always be its name (or class). You can confirm the type by saying this:
Debug.Log( GetType() );
Lets say we have a script $$anonymous$$yScript.js and you want to store an instance of this script inside of another script
// AnotherScript.js
public var myScript:$$anonymous$$yScript;
With public variables that are a script type you can drag any object that contains that script into the slot in the inspector and it will now reference that objects script.
Your answer
![](https://koobas.hobune.stream/wayback/20220613080501im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Getting a reference to a class created in a different gameObject (Javascript) 1 Answer
Folder Trick Doesn't Work: Referencing JS from C# 0 Answers
Your "own" structs ... are they indeed passed by value? 1 Answer
how to pass an int to a function by reference in Javascript ? (as an InOut parameter) 1 Answer