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 stephenjohnellis · Jul 22, 2014 at 10:13 PM · guitexturegridlayout

How to assign textures to specific grid locations?

Hey All,

The code I have below is for building a deck in a memory game. The images that are being assigned for when the card is flipped and matched are fine but I would like to assign different images to each of the back of the cards. Currently, it is assigning the same texture to all of them and so am wondering how I can go about applying a different texture to each grid location for the gui button.

Thanks!

function BuildGrid()

 {

 GUILayout.BeginVertical();
 GUILayout.FlexibleSpace();
 for(var i:int = 0; i<rows; i++)
 {
     GUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     for(var j:int = 0; j<cols; j++)
     {
         var card:Card = aGrid[i,j];
         var img:String;
         if(card.isMatched)
         {
             img = "back";
         }else{
         
         if(card.isFaceUp)
         {
             img = card.img;
         }else{
             img = "set1_1";
         }
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 Aeron0 · Jul 22, 2014 at 11:08 PM

Each card could have 3 variables. One for each image. 1. Front Image - Each card has it's own unique front image 2. Back Image - Each card has it's own unique back image 3. Current Image - The image that would either be front or back

Front and Back images would be your "default" images for each card. These 2 would not change and wouldn't be displayed. Current image would be the image that you would use, display and assign it either Front or Back image.

Another idea for back images is instead of giving each card a default back image, you could have a collection of back images stored in an array or list. And then give a card one of the images from the collection to your current image when you want a card to show a back image. When you want the card to go back to showing the Front image, just assign the card's front image to card's Current image.

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 stephenjohnellis · Jul 22, 2014 at 11:56 PM 0
Share

Thanks for the response. $$anonymous$$ore specifically, I am trying to create a mosaic with the images on the backs of the cards so they need to be fixed to a specific coordinate whereas the other images can be static or random, as they are currently. Below is an example of what I would like to achieve. $$anonymous$$y question is how to assign each individual texture to the specified location in order to complete the mosaic on the back.

Thanks!

avatar image
0

Answer by stephenjohnellis · Jul 23, 2014 at 01:40 AM

In this case, I have a 2x4 grid for a total of 8 images. alt text


grid1.png (259.9 kB)
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 Aeron0 · Jul 23, 2014 at 02:20 AM 0
Share

$$anonymous$$y question is how to assign each individual texture to the specified location in order to complete the mosaic on the back.

The answer is in you question. Each individual texture needs a position variable for the specified location that it wants to be positioned at. You would also need position variables for the specified locations.

// Variables Texture myCard1; Vector2 myCard1_Position = specified location;

Assign specified location to myCard1_Position

avatar image stephenjohnellis · Jul 23, 2014 at 06:23 PM 0
Share

Thanks for the response. So how would I write out those variables? And how would I defined the location? Using Auto Layout, my understanding is that Unity draws the grid out as aGrid [0,0], [0,1], etc. Is that correct? Do I just plug those in?

function BuildGrid()

 {
 GUILayout.BeginVertical();
 GUILayout.FlexibleSpace();
 for(var i:int = 0; i<rows; i++)
 {
     GUILayout.BeginHorizontal();
     GUILayout.FlexibleSpace();
     for(var j:int = 0; j<cols; j++)
     {
         var card:Card = aGrid[i,j];
         var img:String;
         if(card.is$$anonymous$$atched)
         {
             img = "back";
         }else{
         
         if(card.isFaceUp)
         {
             img = card.img;
         }else{
             img = "Set1_1(0_0)";
         }
         }

if (GUILayout.Button(Resources.Load(img),GUILayout.Width(cardW),GUILayout.Height(cardH))) {

         if(playerCanClick)
         {
         FlipCardFaceUp(card);
         }
         Debug.Log(card.img);
         }
     }
     GUI.enabled = true;
     GUILayout.FlexibleSpace();
     GUILayout.EndHorizontal();
 }
 GUILayout.FlexibleSpace();
 GUILayout.EndVertical();

}

avatar image stephenjohnellis · Jul 23, 2014 at 11:55 PM 0
Share

This is also the Card class I established, just not sure how to modify it to add the variables for textures and location.

class Card extends System.Object { var isFaceUp:boolean = false; var is$$anonymous$$atched:boolean = false; var img:String; var id:int;

 function Card(img:String, id:int){
     this.img = img;
     this.id = id;
     }

}

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

How to Assign variable textures using GUI Layout & Flexible Space 0 Answers

Grid layout lags after thousand inserts. 0 Answers

The Game Over creating with audio? 1 Answer

Grid of GUILayout buttons? 1 Answer

Alpha cutoff for a GUI Texture? 2 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