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 mauroc · Jun 24, 2014 at 04:45 PM · inheritanceencapsulation

Basic gameobject inheritance

Hi fellows, small one

Is there a way to have objects inherit properties? I know i can attach a script and it will get to interact with it, but think about this example:

Suppose I have several objects which work as "floor blocks" in my game. They are different, but in the end, they all behave as "floor". Now suppose I want my floor object to behave exactly the same yet they are different objects. So I have grass, wooden floor, asphalt, whatever. I wat them all to share its "floor" nature and maybe differ in some other stuff like "player speed" or i donno, damage rate?

How do you guys handle this inheritance scenario? All i can do is to attach the same script? separatelly to them all?

thanks in advance! UNITY IS AWESOME Mauro

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
0

Answer by jefjohms · Jun 24, 2014 at 05:02 PM

Sounds like prefabs is what you are looking for. http://docs.unity3d.com/Manual/Prefabs.html

Comment
Add comment · 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 mauroc · Jun 27, 2014 at 12:47 AM 0
Share

Ok, it's not really what i was looking for (i was talking about a 100% program$$anonymous$$g related question) but still, I guess that prefabs implement some sort of "the unity way" reusability an inheritace...

thanks @jefjohms

avatar image
0

Answer by Sisso · Jun 27, 2014 at 01:12 AM

Take a look on this question, I have answer some time ago.

http://answers.unity3d.com/questions/710173/good-inheritance-practice-in-unity.html

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 mauroc · Jun 27, 2014 at 01:31 AM 0
Share

It's great, but: How do you actually make your character implement or inherit Damageable or Controllable?

avatar image Sisso · Jun 27, 2014 at 01:52 AM 0
Share

You don't.

In a more component oriented architecture you composite your game object with many Components. In your example you can have the Floor component with basic stuff. So you can create complete independent components that you can attach to create a lava like SlideTextureFloor that change the texture over time, and DamageFloor that have a OnCollider event and cause damage to the player.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

How do i NOT break encapsulation with Unity? 2 Answers

An OS design issue: File types associated with their appropriate programs 1 Answer

Game architecture best practices 3 Answers

OnDrawGizmos for parent and child class 1 Answer

Derived Class Fields 3 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