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 KieranG · Jun 03, 2013 at 10:29 AM · javascriptprefab

Can't add a script to a prefab script: JavaScript

I had a cube that had a script on it. The script cube.js accessed another script main.js. I set up a variable in cube.js

 var mainScript : Main;

that allowed me to drag my Main script onto the cube.js script in the inspector. Then I had to make the cube a prefab and when I did that I couldn't drag the Main script onto the cube.js script.

Is there a work around for this? Or is there a way to just code : mainScript = main.js?

Thanks

Comment
Add comment · Show 1
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 coffiarts · Jun 03, 2013 at 01:55 PM 0
Share

I've problems understanding why you need to assign a script to another script variable in this way: If you want to access non-static variables from that script, you'll probably need a Game Object instance first. If you want to access static variables from $$anonymous$$ain.js, you wont need to assign that script to anything. In that case you can just use $$anonymous$$ain.. Can you give us an example of what you're doing (maybe I am just confused...)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by fueldown · Jun 03, 2013 at 05:49 PM

I think I know what KieranG is trying to do. Basically AFA I understood, he is trying to drop a script in editor which is linked to a gameobject which is not a prefab, on a public script declared in a prefab script.

If this is correct, then what you are doing is not possible by just drag and drop. The reason behind this is that a prefab exists on project level and any other gameobject that is created in the editor or in script (and is not a prefab) exists on scene level. You can not assign anything scene level to anything global as that will cause it to break on scene change.

The work around I use in this case is I make both of them as prefabs. I am not sure that is efficient, but it works. After that you can drop the scripts between these prefabs.

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

16 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

Related Questions

Script is working incorrectly. (rotation) 1 Answer

Prefab Instancing 2 Answers

Prefabs and variables 1 Answer

How to access script variables attached to a prefab at runtime in Javascript? 2 Answers

Unity fire1 prefab in code 2 Answers


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