Search Unity

Change color of individual prefab instance after it was touched

Discussion in 'Prefabs' started by red_fox_boy, Jan 12, 2020.

  1. red_fox_boy

    red_fox_boy

    Joined:
    Jan 6, 2018
    Posts:
    1
    Hello, I started making a 2d game, where an Individual Prefab Instance has to change color after being touched. I'm new to programming in C# and I've scoured the internet for hours but I still can't find an answer which works. I tried adding
    Code (CSharp):
    1. GetComponent<Renderer>().material.color = Color.red;
    to the script on my prefab but it changes the color of all instantiated prefabs. My Unity version is 2019.2.3f1. Please help me.
     
    Last edited: Jan 12, 2020
  2. smolano99

    smolano99

    Joined:
    Apr 14, 2018
    Posts:
    1
    For anyone having this problem, you can create a new material out of the original prefab material and set the material of the prefab to be that newly created material. This will prevent all other instances of the prefab to have the same material since the one modified is a newly created one from the original.