Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Jun 14, 2017 at 04:54 PM by Theby for the following reason:

Outdated

avatar image
0
Question by Theby · Aug 24, 2015 at 11:20 AM · editoreditor-scriptingeditorscript

Give an specific parameter of my GameObject to a Script using the Inspector

Hello everyone, I'm starting to do some editor scripting and then I wonder if you can do the next:

Given a GameObject field of some sort access in the Inspector to all the public fields it may have in his attached scripts, so I can access them inside the script where I inserted this GameObject.

An example of this would be have a general script called "ShooterListener" so inside the script I listen to some value of a given variable specified in the inspector, this way I can change the variable I need the script to listen to without modifying the script itself.

Hopefully it's not too confusing to understand.

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 Scribe · Aug 24, 2015 at 11:32 AM 0
Share

You could use reflection to do this, perhaps also with the use of expression trees. Hopefully those are some good starting points to research

1 Reply

  • Sort: 
avatar image
0

Answer by Foulcloud · Aug 24, 2015 at 09:53 PM

Create a script with one or more public variables. Attach the script to a game object. You can now edit the public variables in the editor. The script will know whatever values you have changed in the editor. You can assign unique values to each different game object. For example, if you have a prefab "car" with a script attached that has a public variable "speed" then you can assign each different car in the scene a different speed.

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

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Recreate default editor look manually without base.OnInspectorGUI [UnityEditor] 2 Answers

Automatically parenting a gameobject when placed in the scene 2 Answers

'CustomEditor' is not a attribute class 1 Answer

Play Unity Editor from VSCode? 0 Answers

Are there any delegate which fires only when a scene has changed in Editor mode, without using ExecuteInEditMode attribute? 0 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