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.

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;
    }

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