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 amilo1003 · Mar 02, 2014 at 09:22 PM · guitexturearraymaterial

How do i get texture from GUI box?

Hi, i have an array of flags(245) and i have them in gui box.I need when i click on the box then the script grabs the texture from the box and put them into the material, any idea?

Thanks

 using UnityEngine;
 using System.Collections;
 
 public class GUIEleveation : MonoBehaviour {
 
     public GUISkin skin;
 
     public string name;
 
     public Texture2D w1, w2, w3, w4, m1, m2, m3, m4;
     public Texture2D[] flags;
     public Texture2D selectedFlag;
 
     public Vector2 scroll;
 
     public int progress;
 
     void OnGUI () {
         GUI.skin = skin;
 
         switch (progress) {
 
         case 0:
             // Name Panel
             GUI.Box(new Rect(Screen.width /2-200,Screen.height /2-200,400,400),"User Info");
             name = GUI.TextField(new Rect(Screen.width/2-150, Screen.height/2-33.3f, 300, 50), name, 20);
             if (GUI.Button(new Rect(Screen.width/2-150, Screen.height/2+100, 300, 50), "Next")) {progress = 1;}
             break;
 
         case 1:
             // Portret Select
             GUI.Box(new Rect(Screen.width/2-400,Screen.height/2-300,800,600),"Portret");
             GUILayout.BeginArea(new Rect(Screen.width/2-400,Screen.height/2-270,800,600));
             GUILayout.BeginHorizontal();
             GUILayout.Box(w1,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.FlexibleSpace();
             GUILayout.Box(w2,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.FlexibleSpace();
             GUILayout.Box(w3,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.FlexibleSpace();
             GUILayout.Box(w4,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.EndHorizontal();
             GUILayout.EndArea();
 
             GUILayout.BeginArea(new Rect(Screen.width/2-400,Screen.height/2-50,800,600));
             GUILayout.BeginHorizontal();
             GUILayout.Box(m1,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.FlexibleSpace();
             GUILayout.Box(m2,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.FlexibleSpace();
             GUILayout.Box(m3,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.FlexibleSpace();
             GUILayout.Box(m4,GUILayout.Height(190),GUILayout.Width(190));
             GUILayout.EndHorizontal();
             GUILayout.EndArea();
 
             if (GUI.Button(new Rect(Screen.width/2-150,Screen.height/2+200,300,50),"Next")) {progress = 2;}
             break;
 
         case 2:
             // Flag Selection
             GUI.Box(new Rect(Screen.width/2-450,Screen.height/2-300,900,600),"Flag");
             GUILayout.BeginArea(new Rect(Screen.width/2-425,Screen.height/2-225,850,450));
             scroll = GUILayout.BeginScrollView(scroll);
             foreach (Texture2D flag in flags) {
                 GUILayout.Box(flag);
             }
             GUILayout.EndScrollView();
             GUILayout.EndArea();
             if (GUI.Button(new Rect(Screen.width/2-150, Screen.height/2+233.33f, 300, 50), "Next")) {progress = 3;}
             break;
 
         case 3:
             // Main Menu
             GUI.Box(new Rect(Screen.width/2-200, Screen.height/2-150, 400, 250), "Main Menu");
             GUILayout.BeginArea(new Rect(Screen.width/2-150, Screen.height/2-75, 300, 150));
             if (GUILayout.Button("Start Game", GUILayout.Width(300), GUILayout.Height(50))) {}
             GUILayout.FlexibleSpace();
             if (GUILayout.Button("Options", GUILayout.Width(300), GUILayout.Height(50))) {progress = 4;}
             GUILayout.EndArea();
             break;
 
         case 4:
             //Options
             GUILayout.BeginArea(new Rect(Screen.width/2-350, Screen.height/2-300, 700, 600));
             GUILayout.Box("Options", GUILayout.Width(700), GUILayout.Height(600));
             GUILayout.EndArea();
             break;
 
         }
     }
 }
Comment
Add comment · Show 2
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 robertbu · Mar 02, 2014 at 09:23 PM 0
Share

A look at your display code would help with answering this question.

avatar image amilo1003 · Mar 02, 2014 at 09:31 PM 0
Share

i have to grab the texture from the box i clicked, flags are at line 66

1 Reply

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

Answer by Jamora · Mar 02, 2014 at 09:42 PM

The best course of action here seems to be to have a button dressed as a box. So your code in the foreach block (line 66) should be

 if(GUILayout.Button(flag,"Box")){ 
     selectedFlag = flag;
 }
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 amilo1003 · Mar 02, 2014 at 09:45 PM 0
Share

Thanks you are awesome!

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

21 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

Related Questions

Problem with material when importing from Blender to Unity 1 Answer

Models From Blender Wont Take Textures 1 Answer

Find Rotation of GameObject : Unity 1 Answer

Menu material error 1 Answer

how to make a material to chrahter (After making texture)??? 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