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 /
This post has been wikified, any user with enough reputation can edit it.
avatar image
0
Question by KenE · Nov 12, 2014 at 02:26 PM · texturematerialobjectscritping

Why are Textures applied to multiple materials script.

My question is about an issue on texturing materials and placing said materials onto objects through script. currently I have two buttons one to place a texture onto the front face of a card and one to place a texture onto the back face.

When I do it the first time it works fine only applying the texture onto the one face. However any subsequent presses and the texture for both materials that are on the faces change.

NOTE each face is a separate game object.

Updated the Code here with Edit: I did end up getting it to texture the front and back of cards and materials separately however I ran into another problem where when I created a copy of my card object and then changed the texture on it again it would then change the texture on the materials attached to the other cards as well. I currently have it set up so that each card has two cube objects back ot back one called "front" and one called "Back" could it be because of the commoon name that it is doing this meaning I have to change the names of said parts of objects?

 // Scripts
         public Colomn1 colomn1Script;
         public Colomn2 colomn2Script;
         public Colomn3 colomn3Script;
         public Card aCard;
 
         //Objects
         public GameObject card;
         public GameObject holdingCard;
         public GameObject colomn1Object;
         public GameObject colomn2Object;
         public GameObject colomn3Object;
         public GameObject frontObject;
         public GameObject backObject;
         public Texture2D frontTexture;
         public Texture2D backTexture;

 frontTexture = new Texture2D (1, 1);
 backTexture = new Texture2D (1, 1);
 colomn1Object = GameObject.Find ("Colomn1");
 colomn2Object = GameObject.Find ("Colomn2");
 colomn3Object = GameObject.Find ("Colomn3");
 card = GameObject.Find ("Card");
 holdingCard = null;
 frontObject = GameObject.Find ("Front");
 backObject = GameObject.Find ("Back");
 
 void CreateMaterial (Texture2D texture, GameObject gameobject)
 {
     // Create a simple material asset
     var amaterial = new Material (Shader.Find ("Diffuse"));
     AssetDatabase.CreateAsset (amaterial, "Assets/Materials/" + cardName + ".mat");
     
     amaterial.mainTexture = texture;
     gameobject.renderer.material = amaterial;
     //gameobject.renderer.material.mainTexture = texture;    
     
     // Print the path of the created asset
     Debug.Log (AssetDatabase.GetAssetPath (amaterial));
 }

   

   
 if (GUILayout.Button ("Add Texture to front of Card")) 
 {
     side = "front";
     if (cardTypeToolbarInt == 0) 
     {            
         cardName = "Play_Play_" + seriesText + "_" + copy.ToString () + "_" + index.ToString () + "_" + side;
     }
     //    camera.SelectCamera (0);
     string file = EditorUtility.OpenFilePanel ("Hello", "", "png");
     if (file.Length != 0) 
     {
         WWW www = new WWW ("file:///" + file);
         www.LoadImageIntoTexture (frontTexture);
         CreateMaterial (frontTexture, frontObject);
     }
 }
 
 if (GUILayout.Button ("Add Texture to back of Card")) 
 {
     side = "back";
     if (cardTypeToolbarInt == 0) 
     {
         cardName = "Play_Play_" + seriesText + "_" + copy.ToString () + "_" + index.ToString () + "_" + side;
     }
     //    camera.SelectCamera (1); 
     string file = EditorUtility.OpenFilePanel ("Hello", "", "png");
     if (file.Length != 0) 
     {
         WWW www = new WWW ("file:///" + file);
         www.LoadImageIntoTexture (backTexture);
         CreateMaterial (backTexture, backObject);
     }
 }


 if (GUILayout.Button ("Save Card too Deck")) {
     
     
     
     
     
     index++;
     if (repeat == true) {
         copy++;
     } else {
         copy = 0;
     }
     if (int.TryParse (randomNumberText, out randomNumber) == true && randomNumberText != "") {
         aCard.RandomNumber = int.Parse (randomNumberText);
         //aCard.name = cardName;
         aCard.Colomn1Header = colomn1Text [0];
         aCard.Colomn2Header = colomn2Text [0];
         aCard.Colomn3Header = colomn3Text [0];
         
         for (int i = 1; i <= 10; ++i) {
             int.TryParse (colomn1Text [i], out aCard.Colomn1Values [i - 1]);
             aCard.Colomn2Values [i - 1] = colomn2Text [i];
             int.TryParse (colomn3Text [i], out aCard.Colomn3Values [i - 1]);
         }
         
         if (deckCount == oldDeckCount) {
             deckCount += 1;
             holdingCard = GameObject.Instantiate (card, new Vector3 (1.00f, 1.00f, deckCount * 0.05f), Quaternion.identity) as GameObject;
             if (side == "front") {
                 cardName = cardName.Remove (cardName.Length - 6);
             } else if (side == "back") {
                 cardName = cardName.Remove (cardName.Length - 5);
             }
             holdingCard.name = cardName;
             var prefab = PrefabUtility.CreateEmptyPrefab ("Assets/Prefabs" + holdingCard.name + ".prefab");
             PrefabUtility.ReplacePrefab (holdingCard, prefab);
             side = "front";
             oldDeckCount += 1;
             
         } 
     } else { 
         EditorUtility.DisplayDialog ("Enter numbers Only.", "Please enter a interger value as random number.", "OK");
         
     }
 }


Comment
Add comment · Show 6
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 GameVortex · Nov 12, 2014 at 03:02 PM 0
Share

You have one texture reference (textureHolder) which you use for both the front and back. So when one changes, the other one naturally changes as well. You should separate them and use individual textures for each side.

avatar image KenE · Nov 12, 2014 at 08:21 PM 0
Share

Alright I added another texture called backTexture and placed it in the code for the button that loads the texture. But now the texture doesn't load anything. I missing something?

avatar image richyrich · Nov 13, 2014 at 10:26 AM 0
Share

You're not making your code easy to understand by having the formatting all over the place. Problems are easier to detect when presented properly

avatar image GameVortex · Nov 13, 2014 at 12:21 PM 0
Share

Cannot help you without you showing us what you specifically are doing. So please update your code here with your new code. Also format it properly.

avatar image KenE · Nov 17, 2014 at 06:14 AM 0
Share

Alright I Updated and edited my code after trying a few things.

I stated the current problem but simple question is if the name of the children of the object are the same and the children hold the materials/textures does that mean I have to rename the children objects because the name is the same all around?

Show more comments

0 Replies

· Add your reply
  • Sort: 

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Making objects invisible 0 Answers

How to make dynamically texturable object model? 0 Answers

How to add texture to Blender objects properly? 2 Answers

Having wrong texture on my model? 1 Answer

Separate textures for identical objects? 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