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 invisibleblack00000 · Nov 21, 2014 at 08:08 AM · variablescustom class

How do I edit variables in an array of a class??

Ok hello um, I've successfully made an array of System. Object in the code below and can edit countless instances of the class Test's variables in the editor however since it's basically my first time threading in these apparently deep waters I have no idea how to modify or access the variables in Test via code, I'm competent in unity script but not so much in c#. I'd very much appreciate it if someone could show or explain how I'd go about doing that.

 class Test extends System.Object {
     var p = 5;
     var c = Color.white;
 }
 var test = Test ();
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 Baste · Nov 21, 2014 at 10:16 AM

First of all, 'extends System.Object' is redundant. Every class always extends Object - if you don't specify what class you're extending, you're still extending Object. If you're extending MonoBehaviour: supprise! MonoBehaviour inherits from Object, or some other class that extends Object.

Now, if you want to edit one of the variables of the test object, there's one huge difference between UnityScript and C#. In UnityScript, variables are public as of default. So when you write 'var p = 5' in the top of a UnityScript script that variable is available outside of that particular class (script)

In C#, variables are private as of default. Which means that to access them outside of the same class (script), you have to declare them as public.

As an example, assume you have to scripts; A and B:

 class Foo {
     public var a = 5;
     var b = 3;
 }

 class Bar : MonoBehaviour {
     public Foo theFoo;

     void Start() {
         //this will work:
         Debug.Log(theFoo.a); 

         //this will not work, as b is a private variable, only accessible inside of the class Foo:
         Debug.Log(theFoo.b); 
     }
 }

That'll give you a start, but you should really try to look at some tutorials. The official ones are okay.

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
avatar image
0

Answer by psycocrusher · Nov 21, 2014 at 07:19 PM

Try this, you need to call system and Serializable or they won't appear in the inspector:

 using UnityEngine;
 using System.Collections;
 using System;
 
 public class Splash : MonoBehaviour {
 
     public static string VersionNumber;
     public static bool  IsFullVersion;
 
 
     public Version SetVersion;
 
     [Serializable]
     public class Version : System.Object {
         
         public string VersionNumber;
         public bool  FullVersion;
     }
 
     void  Awake (){
         
         VersionNumber = SetVersion.VersionNumber;    
         IsFullVersion = SetVersion.FullVersion;
     
     }
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

Build problem, missing variables 1 Answer

In-Game Console and Permanent Variable Changes 1 Answer

Is there a list of variable attributes for C#? 2 Answers

Problem storing GameObject reference in script - PUN 0 Answers

how can i write this properly 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