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 Geine · Sep 08, 2012 at 05:48 AM · gameobjecttexturearray

arrays / textures help

ok i have 2 arrays lets say

 x:GameObject[] = new GameObject[4]

and then i have

 y:Texture[] = new Texture[4]

how do i access the gameObjects Textures in "x" to display them in "y".

sorry, just trying my best to do scripting BTW its in javascript,

thanks in advance to those who will answer.

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

1 Reply

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

Answer by save · Sep 08, 2012 at 08:17 AM

To access an object's main texture you go through the renderer's material.

 for (var i = 0; i<x.Length; i++) {
     y[i] = x[i].renderer.material.mainTexture;
 }

You can also go by the property name in the shader by using the GetTexture-function:

 var tex : Texture = renderer.material.GetTexture ("_BumpMap");


Remember that the array y doesn't have to be public, you could make it static or private (depending on your need for access level) and resize it before you iterate through the x array.

 y = new Texture[x.Length];

Comment
Add comment · Show 3 · 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 Geine · Sep 08, 2012 at 09:17 AM 0
Share

dude have an error that says : "UnassignedReferenceException: The variable x of 'Js_Test' has not been assigned. You probably need to assign the x variable of the Js_Test script in the inspector." what to do?

avatar image save · Sep 08, 2012 at 10:12 AM 0
Share

What it means is that you haven't assigned the variable x (there's nothing in the array or you're trying to point to an element that isn't present).

Have you assigned the variable in the Inspector? If it's static have you declared a new GameObject[] and filled the array? Else are you sure you have an element where you point to the array? - The last thing often happens when stopping rule is larger than the actual elements in the array

 x = new GameObject[10]; //0 - 9
 var someNumber = 10; //0 - 10
 for (var i = 0; i<someNumber; i++) 
avatar image Geine · Sep 08, 2012 at 11:41 AM 0
Share

thanks again :D i'll go check it again

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

9 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Resources.Load Problem 1 Answer

How do I texture objects in an array with different textures? 1 Answer

Can't add GameObjects to ArrayList 1 Answer

Keep adding targets to a list 2 Answers

How do I check multiple gameObjects transform positions? 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