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 /
  • Help Room /
avatar image
0
Question by Kwietniak · Dec 18, 2015 at 07:09 PM · arrayclassobjects

Assaigning objects in class

When I try to assigning "Attendance Items" in the class:

 public class Attendance
 {
     public Camera eventCamera;
     public GameObject eventTrigger;
     public GameObject msgZeCanvas;
     public obslObj [] AttendanceItems ;
 }

whose elements are:

 public class obslObj 
 {
     public GameObject items;
     public Rigidbody rbItem;
 }

when I try iteration in loop I have problem, because I cannot relate to the length of the array's function.

 Lenght:
 for (int i=0; i<Attendance.AttendanceItems.Length; i++)

as well as

 foreach (obslObj item in Attendance.AttendanceItems)

which are included in another class:

 public class AttendanceEventScript: MonoBehaviour

When I try to compile I get the error:

AttendanceEventScript.cs (39,69): error CS0120: An object reference is required is access non-static member `Attendance.AttendanceItems'

Any ideas?

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
2

Answer by Dave-Carlile · Dec 18, 2015 at 07:23 PM

You're trying to work with the Class, but you must create an Instance of the class and work with that. The class is just a data type.

 // create an instance of the Attendance class
 Attendance attendance = new Attendance();  

 // now you can access properties...
 attendance.eventCamera = myCamera;  


Now, inside of your Attendance class you have an array of obslObj. That array reference is going to start out as null, so you have to create it and specify a length. If it's a constant size, the easiest way is when you declare the Attendance class...

 public class Attendance
  {
      ...
      // allocate the array using new...
      public obslObj [] AttendanceItems  = new obslObj[10];  
  }

Now you can access the array...

 Debug.Log("length=" + attendance.AttendanceItems.Length);
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 Kwietniak · Dec 18, 2015 at 10:08 PM 0
Share

Thank you very much!!

avatar image
0

Answer by Halucynek · Dec 18, 2015 at 10:16 PM

Really thx for help

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

36 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 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

Having problems with custom objects in my array - BCE0019 0 Answers

NullReferenceException: Object reference not set to an instance of an object 0 Answers

Unity 3D C# - Making Classes Act Like An Array 3 Answers

[SOLVED] Increase and Decrease size of Class Array in Unity C# 1 Answer

How to get an object (that is a prefab) from an array and instantiate it (C#) 1 Answer


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