Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 marac0008 · Aug 23, 2017 at 09:41 AM · scenematerialsplatformermaterial colorcolors

Changing material color between scenes

Hi all, I have been working on a platformer game and was wondering something. So here's the problem, I created multiple materials for multiple things (one for player, one for foreground, one for traps, one for fire traps and so on) and when I want to change the color for example for all traps I just change color in material and it changes color for all trap objects in the scene, which works great, but the problem is, if I change color of this material in second scene, it will change colors in all scenes. Now the question is, is there any way I can solve this without creating separate materials for every scene, because that would result in excessive amount of materials? This is at the moment the only thing I can think of (except doing it with script by changing colors of material at the start of the scene, which will have to be an option if I don't find anything else).

I hope I explained it well. Thank you in advance :)

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
0
Best Answer

Answer by SteenPetersen · Aug 23, 2017 at 10:02 AM

Might wanna try and just change the material color depending on the loaded scene. by making some sort of materialcolor check in the heirarchy.

 public class MaterialColors : MonoBehaviour {
         public int sceneNumber;
         public Material trapMat;
         public Color color1 = Color.red;
         public Color color2 = Color.green;
         public bool materialLoaded = false;
     
         void Update(){
     
        if(!materialLoaded){
                 CheckMaterialColor(sceneNumber);
          }
 
         }
 
         public void CheckMaterialColor(int scene){
 
                  switch(scene){
                  case 1: 
                            trapMat.color = color1;
                            materialLoaded = true;
                            break;
                  case 2: 
                            trapMat.color = color2;
                            materialLoaded = true;
                            break;
                  }
         }

then just remember to set the bool materialLoaded to false when loading a scene.

Comment
Add comment · Show 2 · 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 marac0008 · Aug 24, 2017 at 12:12 AM 0
Share

I had similar thing in $$anonymous$$d, creating script that would change material parameters at the beginning of the scene, but I thought I might solve my problem without using script, but I guess not.

Anyway, thank you for your help :)

avatar image Spaniel · Nov 13, 2017 at 11:29 PM 0
Share

This is also a bad answer. You can simply subscribe to the change scene callback and then do it like this. Why would you do it in Update()?

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

81 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 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 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 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

Trail Colors ?? 0 Answers

Disable 1 of the 2 Materials from the same Object. 1 Answer

Material cant be seen until Im very close 1 Answer

Platform color to kill player if player does not match 2 Answers

materials dont look the same in blender and in unity 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