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 /
  • 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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Textures are pink on iOS Build 0 Answers

Terrain texture layers not working after universal render pipeline install,Textures on terrain not showing after removing universal render pipeline 0 Answers

Can someone change this array to use materials instead of textures 1 Answer

how to prevent light going though walls with urp in 2d renderer 0 Answers

How to load material onto sphere? 1 Answer


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