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 /
This question was closed May 07, 2018 at 08:10 AM by Myth for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Myth · Aug 09, 2014 at 12:56 AM · prefabaddcomponent

Auto Build Script

I am approaching the tedious part of creating my game - creating prefabs and changing settings for a large number of objects. These objects (i.e. different strike-craft) have all got the same scripts on them but there are many many scripts to add to each one.

I need a way (or the correct syntax) to add ONE script to an object and have it add the rest - similar to @script require component.

Any suggestions?

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

  • Sort: 
avatar image
0
Best Answer

Answer by Myth · Aug 19, 2014 at 02:22 AM

The code is:

 [RequireComponent(typeof(StrikeCraftFlightInput))]

Where StrikeCraftFlightInput is the name of the script.

(for C#)

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
avatar image
1

Answer by rutter · Aug 09, 2014 at 01:09 AM

Editor scripting is a lot like any other scripting, except that it runs in the editor. Some of them also make use of the UnityEngine namespace -- those ones should go in the Editor folder.

For example, you could create a MenuItem that adds your scripts:

 #pragma strict
 
 @MenuItem("Extras/Add Components")
 static function AddScripts() {
     for (var transform : Transform in Selection.transforms) {
         var box = transform.gameObject.AddComponent(BoxCollider);
         box.size = Vector3.one * 5;
     }
 }

The "Extras" menu will appear in the top bar of your Unity editor window (near "File" and so on). Sometimes it won't show up at first until you click another menu.

Editor scripting is very powerful, but not as well documented as I'd like.

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 Myth · Aug 09, 2014 at 01:30 AM 0
Share

can you make an example that has the scripts "craftInfo.cs" and "generator.cs" in it. I can add the other 37 scripts myself once I understand this better

avatar image gjf · Aug 09, 2014 at 06:19 PM 0
Share

37? that's an awful lot...

Follow this Question

Answers Answers and Comments

22 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

Related Questions

Adding Prefab Components 1 Answer

The name 'Joystick' does not denote a valid type ('not found') 2 Answers

Show and Hide a prefab or GameObject 10 Answers

How to find a prefab in another scene? 1 Answer

very weird NullReferenceException error causeing one script to break another 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