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 Oinobareion · Nov 30, 2010 at 11:40 AM · errorarraysyntax-errorbce0019

Accessing array in another script - Error message

I've got one script which defines an array (GUI_Main.js):

var thumbnailTextures : Texture2D[];

And a script (attached to another game object) that tries to access the first element from the thumbnailTextures array (AnotherScript.js):

GameObject.Find("GUI_Main").thumbnailTextures[0] = obj.renderer.material.mainTexture;

And I am getting the error message: Assets/Take Script.js(49,53): BCE0019: 'thumbnailTextures' is not a member of 'UnityEngine.GameObject'.

I think, I didn't really understand the concept of accessing variables in other scripts. Can somebody help me? Thx.

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

Answer by Maarten · Nov 30, 2010 at 11:47 AM

You are returning a GameObject. You should use GameObject.Find("GUI_Main").GetComponent("ScriptName").thumbnailTextures[0]

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 Oinobareion · Nov 30, 2010 at 12:04 PM 0
Share

Thank you! Works fine. Now i finally understand the concept :-)

avatar image
1

Answer by Proclyon · Nov 30, 2010 at 11:47 AM

Most people don't so don't worry , it's something you learn by programming a lot. And a case of aspirin in the start.

The quickest way is to make an object instance of that script

class Foo() { public int x = 3; private int y = 4; }

class Bla() { //Calls default constructor just ignore the whole constructor thing for now Foo myFooObjectInstance = new Foo();

 //Allowed
 int myBlaInt_X = myFooObjectInstance.x;

 //NOT ALLOWED! private is blocking acces
 int myBlaInt_Y = myFooObjectInstance.y;

}

An array can be accesed the same way but you should really just store the array in where you need it and acces it there or use a get{}set{} which helps with reading/writing and letting the other script know you are "potentially" messing it up (But if all that's to much information for now just forget it ok)

EDIT:

It was just brought to my attention you may not have any use for C# , I think it's a bit of a waste to just delete this answer but I would like to apoligize for the sloppyness of the answer. I'm afraid I can not do much in JS support but wish you good luck!

Comment
Add comment · Show 4 · 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 Maarten · Nov 30, 2010 at 11:52 AM 0
Share

You are using C#, and the poster is using Javascript.

avatar image Proclyon · Nov 30, 2010 at 12:05 PM 0
Share

oh my , didn't even notice. So used to answering in C#!

Good point. Going to leave it here for posterity and edit and apoligy

avatar image Oinobareion · Nov 30, 2010 at 12:05 PM 0
Share

Thank you for the short introduction :-)

avatar image Oinobareion · Nov 30, 2010 at 12:10 PM 0
Share

No problem! I am sure, the C# code will help other users as well...

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

No one has followed this question yet.

Related Questions

I got a major question 1 Answer

Getting an error while script reference says it's ok 1 Answer

Getting list music array 1 Answer

error for array functions 2 Answers

Enabling / Disabling C# Scripts - Why am I getting the error "not a member of 'UnityEngine.Component'"? 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