• 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
Question by nickolouse · Sep 11, 2014 at 08:19 PM · javascriptinspectorclassinheritance

Change a Class in the inspector

I have a class with my basic enemy AI in it and I have created several AIs that inherit from that one. What I would like to be able to do is create a new prefab throw my script that uses the class on it and then drag my desired AI to the variable in that script. However I cannot find a way to do t$$anonymous$$s. I have done some Google searches with no luck.

Comment

People who like this

0 Show 0
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

Answer by jtsmith1287 · Sep 11, 2014 at 09:17 PM

Sounds like what you're looking for are Interfaces. Have a look at the documentation.

Essentially, you'll want all of your AI scripts inheriting from an IArtificialIntelligence (I wrote it out cause IAI looks dumb, lol) that enforces methods and properties shared on all AI scripts. Then you can simply set an IArtificialIntelligence AIscript; as a class member and shoud be able to drag and drop anyt$$anonymous$$ng inheriting from it into that box. :)

Spend some time to understand Interfaces. They're wildly useful and amazing, and are seriously underrated.

EDIT: Ok, lame. I just noticed the javascript tag. T$$anonymous$$s won't help you. In fact, there may not be a way to do what you want in Javascript. So I know that t$$anonymous$$s isn't the answer you're looking for, but please hear me out. Javascript is NOT, I repeat NOT a good language for developing large games in. I'm honestly surprised Unity implements it at all. I kind of feel like doing so was a marketing t$$anonymous$$ng to attract more users. I don't dislike javascript -- it's pretty cool, but not for Unity. It's fairly similar to C#, so take some time to get to know C# and you'll find yourself dealing with significantly less bugs. Anyway. Good luck to you!

Comment

People who like this

0 Show 1 · 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 nickolouse · Sep 11, 2014 at 11:52 PM 0
Share

Thank you for the response. I'm not so uncomfortable with C# actually. When I started this project with a friend I chose JS because I thought it would be a little easier for him to follow if he needed to do anything(he's an art guy). I also chose it because I had a little more experience with JS. I'm going to read up on your proposed solution. I may switch to C# for future projects.

I have another solution in mind but I want to see if any of you guys with more experience can offer a different, better solution.

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

24 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

Related Questions

Is it possible to create a script dinamic like animation>size controling the Elements variables? 1 Answer

JS class inheritance woes. i.e. wtf? 2 Answers

Static array with custom class? 1 Answer

Help with sorting values from a class 2 Answers

How do I show a Classes Vars in the inspector (Javascript)?? 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