• 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 WilcoSnel · Jun 27, 2012 at 08:40 PM · materialscenechangeother

Change Material in other Scene by Scripting

I have created a GAME. I created 2 scenes. A MENU and the actual GAME. In the MENU I can change colors with the understanding script.

 var StockCarMats : Material[];
 var StockWheelMats : Material[];
 var Car : GameObject;
 var FLWheel : GameObject;
 var FRWheel : GameObject;
 var BLWheel : GameObject;
 var BRWheel : GameObject;
 var Oranje : Material;
 var Blauw : Material;
 var Zwart : Material;
 var Geel : Material;
 var Wit : Material;
 var Rood : Material;
 var CarTurn : Transform;
 
 var Livery = 1;
 
 function Livery2()
 {
     var CarMats = Car.renderer.materials;
     var FLWheelMats = FLWheel.renderer.materials;
     var FRWheelMats = FRWheel.renderer.materials;
     var BLWheelMats = BLWheel.renderer.materials;
     var BRWheelMats = BRWheel.renderer.materials;
     
     CarMats[0] = Oranje;
     CarMats[1] = StockCarMats[1];
     CarMats[2] = StockCarMats[2];
     CarMats[3] = StockCarMats[3];
     CarMats[4] = StockCarMats[4];
     CarMats[5] = StockCarMats[5];
     CarMats[6] = Zwart;
     CarMats[7] = StockCarMats[7];
     CarMats[8] = StockCarMats[8];
     CarMats[9] = StockCarMats[9];
     CarMats[10] = StockCarMats[10];
     FLWheelMats[0] = Zwart;
     FLWheelMats[1] = Wit;
     FLWheelMats[2] = StockWheelMats[2];
     FRWheelMats[0] = Zwart;
     FRWheelMats[1] = Wit;
     FRWheelMats[2] = StockWheelMats[2];
     BLWheelMats[0] = Zwart;
     BLWheelMats[1] = Wit;
     BLWheelMats[2] = StockWheelMats[2];
     BRWheelMats[0] = StockWheelMats[2];
     BRWheelMats[1] = Zwart;
     BRWheelMats[2] = Wit;
 
     Car.renderer.materials = CarMats;
     FLWheel.renderer.materials = FLWheelMats;
     FRWheel.renderer.materials = FRWheelMats;
     BLWheel.renderer.materials = BLWheelMats;
     BRWheel.renderer.materials = BRWheelMats;
 }
 
 function OnGUI()
 {
 
 if(GUI.Button(Rect(10,90,70,30),"Livery 2"))
     {
     Livery2();
     Livery = 2;
     }
 }

Of course when I start the GAME Scene this changed color is lost. I tried to fix this with another script in the GAME Scene.

 if(GUI_Script.Livery == 2) {
     GUI_Script.Livery2();
     }

This brings up some errors. Makes sense since I pretty much have to change all the variables to static variables. But when I do this to all the needed variables, Unity loses the links to GameObjects and Materials in the Inspector. And then it generates errors becaus of the lost links. And I can't restore the links in the Inspector because they don't show up until I revert all the static var's back to normal variables and delete the second script.

Is this a bug? Is there a maximum to static var's to define? Can't a static var be a GameObject, Material or array? Or is there another solution?

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

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

change scene with keypress?? 1 Answer

How can I get or set textures on a material other than the main texture? (eg, the bump map) 1 Answer

making texture less enviorment 1 Answer

referring to a particular material 0 Answers

Everything turned white . . . 0 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