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 /
avatar image
0
Question by akvisgaard · Apr 18, 2016 at 06:59 AM · inheritanceclassesinherit

I can't make my sub class inherit from my base class [Mac + MonoDevelop]

Im currently building some UI elements in Unity, and I have different scripts on various elements in the UI. I have the following classes in two separate files:

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class loadTxt : MonoBehaviour {
 
 
     public string textFile = "text";
     string textContent;
 
     List<string> productList;
     private string[] productArray;
 
 
     void Start () {
 
         TextAsset txtAsset = (TextAsset)Resources.Load (textFile);
         textContent = txtAsset.text;
 
         productArray = textContent.Split (';');
 
         productList = new List<string> ();
 
         for (int i = 0; i < productArray.Length; i++) {
             productList.Add (productArray [i]);
         }
     
     }
 
     void RemoveFromList(int index) {
         productList.RemoveAt (index);
     }
 
     public string TextContent {
         get { return this.textContent;}
         set    { textContent = value; }
 
     }
     
 
     void OnGUI () {
         for (int i = 0; i < productList.Count; i++) {
             GUILayout.Label (productList[i]);
         }
 
     }
 }
 
 class onClickRemove : loadTxt {
 
     textContent = "new_value";
 
     public void onClick() {
         TextContent = "other_value";
     }
 }


For some reason I can't inherit any variables or functions in my sub class "onClickRemove" from my base class "loadTxt". If I type in a change the value of the variable "textContent" in my sub class, the program does not autocomplete the function name and if I type in the change anyway I get an error saying the variable does not belong in that content, which basically means the sub class has not inherited the values from its base class.

What am I missing to get it to work, Ive searched to find an explanation to this problem but no fix have worked so far.

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 giorashc · Apr 18, 2016 at 07:10 AM 0
Share

what is the purpose of textContent = "new_value" in loadTxt? since textContent is private it cannot be accessed at this point

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by antx · Apr 18, 2016 at 07:41 AM

Your subclass has "textContent" without a type. "textContent" in your base class is not public nor protected. So your subclass does not see it.

Also class and function names should start with a capital letter.

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 akvisgaard · Apr 18, 2016 at 08:25 AM 0
Share

Arh I feel stupid, O$$anonymous$$ I thought that the privacy declaration on variables and functions only had to do with accessing its value from external applications such as Unity e.g

Thank you!

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Why use inheritance? 3 Answers

Inheritance and using GetComponent 2 Answers

Unity exports my derived class, but not its base class (C# OOP) - Is there a workaround? 0 Answers

Create a new script object from a class which inherits from MonoBehavior 4 Answers

Won't excecute the overwrited function 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