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 yxyx136 · Oct 25, 2014 at 08:40 PM · classinheritanceboo

Multi inheritance in Boo

Hey Guys, is there any way or alternative to inherit from multible classes? Basically I want to have to classes, a player class and a character class, since a character can be also another player I want to inherit the player class from the character class. Here's my Code: Character.boo

 import UnityEngine
 
 public class Character (MonoBehaviour): 
 
     health as single     = 100
     maxHealth as single  = 100
     
     stamina as single    = 100
     maxStamina as single = 100
     
     def kill():
         pass
     
     def respawn():
         health  = 100
         stamina = 100


Player.boo

 import UnityEngine
 
 public static class Player (MonoBehaviour, Character): 
     
     def Update():
         pass

The current error is "Assets/Scripts/Player/Player.boo(3,44): BCE0001: The class 'Player' already has 'UnityEngine.MonoBehaviour' as its super class. "

Thanks in advance!

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
Best Answer

Answer by Bunny83 · Oct 25, 2014 at 09:50 PM

If you derive your Player from the Character class the Player will also be a MonoBehaviour since the Character class os derived from MonoBevhaviour. So just derive your player from Character and you'll be fine.

.NET / Mono only allow one base class per class, there's no way around that.

Keep in mind that MonoBehaviour is also derived from Behaviour and Behaviour from Component and Component from UnityEngine.Object. So your complete class chain would look like this:

Player -> Character -> MonoBehaviour -> Behaviour -> Component -> UnityEngine.Object -> System.Object

edit
I just reread your title. You said you want to use multi inheritance but what you actually need is simple inheritance, at least what we can understand from your description.

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 Bunny83 · Oct 25, 2014 at 09:55 PM 0
Share

PS: $$anonymous$$eep in $$anonymous$$d that every Player instance is also a Characer as well as a $$anonymous$$onoBehaviour and a Component.

However not every Character has to be a Player. You could create another class called NPC which is also derived from Character. So an NPC and a Player are both a Character but NPC and Player are not interchangable.

avatar image
0

Answer by Kiwasi · Oct 25, 2014 at 09:43 PM

No. This is not possible.

There are two plausible solutions. Your class can inherit from player, player can inherit from monobehaviour. Or you class can implement an interface.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

BOO: Unexpected Errors 1 Answer

Inherited member variables not set to base value c# 1 Answer

Loading component by superclass. 1 Answer

Public variables from another class's nested class 1 Answer

How to make a custom class inherited from Unity's GUI? 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