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 $$anonymous$$ · Jan 04, 2015 at 09:00 AM · javascriptgetcomponentclassclasses

Access a script that has NO class?

I have a script I downloaded, and it works great, however it has NO class declaration!

I want to access it from another script, to change its variables, but I can't figure out how to use transform.GetComponent to access the script, because without a class delcaration, the script has no name? I tried GetComponent with its file name, but that didn't work.

The script is javascript (js). I'm calling it from a C# script. Hopefully that's allowed.

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

2 Replies

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

Answer by tanoshimi · Jan 04, 2015 at 09:07 AM

(Not quite sure how you know it "works great" when you haven't got it to work, but never mind)

UnityScript files, unlike C#, do not have explicit class declarations. You simply write Start(), Update() functions etc. in the body of the script and attach it to an object - it automagically creates a wrapping class that inherits from Monobehaviour.

To call from C#, place your .js script in the Standard Assets folder of your project to ensure it is compiled first, then simply attach to an object and call it using GetComponent as usual.

Comment
Add comment · Show 3 · 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 $$anonymous$$ · Jan 04, 2015 at 09:22 AM 0
Share

Thanks for the answer. I tried putting the file directly into the Assets/Standard Assets/ folder, so that it is now located at [project root]/Assets/Standard Assets/ParticleLines.js --- and then when I type transform.GetComponent, intellisence does not find it, I assume it isn't working. I also tried the same steps, but using the Plugins folder ins$$anonymous$$d, no luck there either. I'm trying to call it from a c# script that inherits from monobehavior. Any idea what I'm doing wrong?

avatar image tanoshimi · Jan 04, 2015 at 09:32 AM 0
Share

Intellisense probably won't spot it. Use the force, Luke, and just type it anyway:

 GetComponent<ParticleLines>().WhateverTheNameOfTheFunctionInThatClassIs();
avatar image $$anonymous$$ · Jan 04, 2015 at 11:11 AM 0
Share

YAY! The force worked.

avatar image
0

Answer by Kiwasi · Jan 04, 2015 at 09:03 AM

With JavaScript the class name is the same as the file name.

Expect plenty of headaches working with the two languages. You generally have to put the JavaScript file into the plugins folder for this to work.

Comment
Add comment · 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

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

25 People are following this question.

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

Related Questions

Multiple classes inside each other 1 Answer

Accessing a variable inside a class inside other script... 2 Answers

Linking prefabs to classes that are not attatched to gameobjects 1 Answer

Custom JS class error - function is not a member of the class 2 Answers

hot to make classes and why ? 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