Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Level issues

Discussion in 'Editor & General Support' started by AndyNeoman, Dec 2, 2014.

  1. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    Hi all,

    I have a simple side scrolling shooter with two levels, they are almost identical apart from backgrounds at the moment so I created one, then duplicated and renamed, changing the background textures on the second one.

    The problem is every time I change the background on one the other magically changes too. Any idea how to stop this or what solution I can do other than have to not duplicate levels?
     
  2. Ambro

    Ambro

    Joined:
    May 29, 2013
    Posts:
    34
    I suppose that you are changing the texture of a material which represents your background. If you have duplicated it, the two background are referencing/using the same material. When you change its texture, it will be updated to all others renderer that uses this material.

    You need to create a new material which contains your second texture and apply it to one of your two background. You will have two distinct materials with their own textures.
     
    aaronhm77 and AndyNeoman like this.
  3. AndyNeoman

    AndyNeoman

    Joined:
    Sep 28, 2014
    Posts:
    938
    I fixed it by creating new named backgrounds but i think your method would have been simpler. Am I right in thinking you would just change the material in the mesh renderer to the correct texture?
     
  4. Ambro

    Ambro

    Joined:
    May 29, 2013
    Posts:
    34
    Yes, that's it !

    Another method would be to create a script that initialize the material.mainTexture with a custom texture that you put in the inspector. It would automatically create another instance of the current material and apply the new texture to it. Downside is that you can't visualize it outside Play mode.
     
    AndyNeoman likes this.