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 Zobikhan · Dec 20, 2017 at 11:42 AM · unity 5scene change

How to change color of the car in scene02 on button click of scene01? how I should use 'static' keyword.

(new to unity) My scene_01 have four buttons for four different colors, I want to change the color of the car happens in scene_02 with respect to selected color. I don't really know how to write script for accessing car's body material from scene_01.

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

Answer by Legend_Bacon · Dec 20, 2017 at 05:31 PM

Hello there,

You have several options there. Either:

  • Make a Data Holder object with DontDestroyOnLoad, or

  • Use the player prefs (or any kind of data saving, really) to get values from/to different scenes. For a color, you could save a Hex value as a string PlayerPrefs.SetString("CarColor", myHexColorAsString);. To load it, you could then use string colAsString = PlayerPrefs.GetString("CarColor"). And finally, to parse it follow this link: Hex Colors in Unity.

I hope that helps!

~LegendBacon

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 Legend_Bacon · Dec 20, 2017 at 05:35 PM 0
Share

I just noticed the last part of the question, about the material.

To access a GameObject's material and change its color, you can go:

 myGameObject.GetComponent<Renderer>().material.color = myColor;
avatar image
0

Answer by Prastiwar · Dec 20, 2017 at 04:14 PM

You just need reference to car's material that you have in folder structure, so you can change it's color easily. Example:

 [SerializeField] Material carMaterial;
 
     void OnRedButton()
     {
         carMaterial.color = Color.red;
     }
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 Zobikhan · Dec 20, 2017 at 05:12 PM 0
Share

appreciated but the problem I am facing is to access the GameObject of another scene on button click from different scene.

avatar image Prastiwar Zobikhan · Dec 20, 2017 at 08:00 PM 0
Share

Okey, to change car's material you don't have to access to car. $$anonymous$$aterials can be accessed from everywhere, so I don't really understand your problem. $$anonymous$$aybe this can help you: if you want access to car in scene_02 (I guess it's main game scene) you can make reference in scene_01 with, DontDetroyOnLoad, set $$anonymous$$aterial Color and then in scene_02 instantiate car from this specific reference. Also you can check Legend_Bacon's solution with PlayerPrefs

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

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

How to save changes to a scene when moving to another scene 1 Answer

Massive lag when changing scenes on Android. 1 Answer

unity and interfacing with a real hardware 0 Answers

How backward-compatibly write NotificationServices in Unity 2 Answers

Byte[] to AudioClip 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