• 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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



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

Unload from memory - GameObject in an array? 1 Answer

How Repeatedly Game Object store in array??How Identify?? 0 Answers

Select colour then change texture 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges