Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by xEnOnn · Sep 01, 2012 at 05:56 AM · javascriptreference

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?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

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
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xEnOnn · Sep 01, 2012 at 07:16 AM 0
Share

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?

avatar image OperationDogBird · Sep 03, 2012 at 12:40 AM 0
Share

@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

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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

Unity3d Javascript Reference Script Variable 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges