• 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 /
  • Help Room /
avatar image
1
Question by Mokenister · Jan 12, 2016 at 04:53 PM · texturerendererrender textureskin

How do I make a change skin button for my game

(c sharp) So, I have a 3d platformer ball game, where I want to implement a "change skin" system where you will be able to click a button to chose texture for the entire game for your player (change texture of a prefab I guess). I don't know how to make this script but I know that you can change color by doing
Renderer myRender;
myRender.material.color = Color.yellow;
but I don't know how do i do the same thing but with a texture. Can someone please help me because this is a thing I would like the most in my game. Thank you so much :)

Comment
Add comment · Show 1
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 vintar · Jan 12, 2016 at 08:20 PM 0
Share

myRender.material.mainTexture = myTexture;

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by TheFloatingSheep · Jan 12, 2016 at 08:21 PM

You need a Texture2D variable then... you can use SetTexture(propertyName: string, texture: Texture); or SetTexture(nameID: int, texture: Texture);

The first propriety can be a string with the name of the texture you wanna change. For example if you're using a shader with 3 textures... like... a simple texture, a normal map and a Heightmap, you're gonna need to use "_MainTex" and other names. The easiest way is using integers. For example, if the base texture is the first one, you write the first propriety as 1. The texture is gonna be your Texture2D variable. You can have a few textures in your unity project and have a specific var for every one of them or you could use an array. I'm using javascript so i'm not sure how it works in C Sharp, in javascript is: var Name : Texture2D[];

And you can add how many textures you want in the inspector, then you set the texture of the object to Name[int]; For example if you wanna set it to the 4th texture u have to do it like: SetTexture(1, Name[4]);

Everything should be the same in C Sharp besides the variables.

I looked it up, i think it's: public Texture2D[] Name; So...

 public Texture2D[] Name;
 
 void Start () {
  GameObject.FindGameObjectWithTag("tag").SetTexture(1, Name[4]);
 }


Good luck ;)

Comment
Add comment · 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
0

Answer by Mokenister · Jan 13, 2016 at 03:18 AM

So Will this work if I make a button in the main menu, and then switch scenes to the actual game? Will the texture stay of reset? Thanks for the help though :) @TheMiningSheep

Comment
Add comment · 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

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

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Color bleeding across pixels 1 Answer

Pink lines 0 Answers

Interaction with renderer Texture 0 Answers

Combining a projected texture with a render texture 0 Answers

Textures are pink on iOS Build 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges