Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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 /
avatar image
0
Question by Ochreous · Jun 12, 2013 at 01:47 AM · c#texturecombining

C# combining Two Textures

Hi everyone, is it possible to combine two textures? I have two textures, one that is an item and the other that is a selector . I want to make it so when the GUI.Button is clicked it combines the selector's and the item's textures together so that the item looks like it has been selected. I have tried itemTex+selectorTex but the console gives me an error saying that I can't use the plus like that.

 using UnityEngine;
 using System.Collections;
 
 public class example : MonoBehaviour {
     public Texture itemTex;
     public Texture selectorTex;
     void OnGUI() {
 
         if (GUI.Button(new Rect(10, 10, 50, 50), itemTex)){
         //itemTex = itemTex+selectorTex
     }
 }
Comment
Add comment
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

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by cregox · Jun 12, 2013 at 04:55 PM

I didn't even knew textures could be combined as robertbu said, but I also agree probably, in your case, the best option is provide two textures ready to simply switch.

I also don't know why nobody mentioned using the built-in Decal shader. You can assign 2 textures there, which will be combined. It's exactly what it's made for, and it can have its usage when you have lots of different combinations.

Comment
Add comment · Show 1 · 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 luisquid · Jun 14, 2017 at 10:31 PM 0
Share

$$anonymous$$an, I've been going crazy about this issue for the past 2 months! Completely forgot about that shader. Thank you!

avatar image
1

Answer by robertbu · Jun 12, 2013 at 02:30 AM

Textures can be combined, but it is an expensive and a bit ugly operation. You would have to make them both a Texture2D, they would have to be read/write enabled, you would need to pull the data out from both of them, combine the data by cycling through all the pixles, and then insert that data either back into an existing texture or a new one. And if they are a different size, you would need to do some not nice index calculations.

It would be better if you provided two forms of your itemTex, one selected and one with no selection. At runtime, you would switch between the two.

Comment
Add comment · Show 3 · 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 Ochreous · Jun 12, 2013 at 03:43 AM 0
Share

Ok, thanks for the info. I honestly thought creating two textures would be more consu$$anonymous$$g

avatar image iwaldrop · Jun 12, 2013 at 03:50 AM 0
Share

You can easily assign each texture to their own planes and put one in front of the other. This would work best with an orthographic camera, of course. The selecter texture should use a transparent shader. Then you can move your selecter image to the same x,y coordinates as the object that is selected to achieve your effect. And it would be a whole lot more performant than generating textures at runtime; both computationally and with respect to ram.

avatar image Ochreous · Jun 12, 2013 at 03:55 AM 0
Share

I'm using this for Unity's GUI though which doesn't happen in the game scene.

avatar image
1

Answer by TheDarkVoid · Jun 12, 2013 at 09:27 PM

A simpler method to achieve your desired effect is to just render the section texture about your item texture, that is what most games use. You can also try render it behind the item for a different effect.

Comment
Add comment · Show 1 · 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 cregox · Jun 12, 2013 at 09:53 PM 0
Share

Render above, yeah. That's what iwaldrop already commented. In his case, would need to toy with depth, since they're GUI elements, but it ain't that simple. Seems like it would only work for different scripts. If they were GameObjects, simply moving the Transform would obviously work.

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

18 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

null texture passed to GUI.DrawTexture 0 Answers

C# cannot convert 'char' expression to type 'UnityEngine.Texture' 1 Answer

How to load image from redirected server URL? 1 Answer

how to make high quality textures with low size of downlaod 1 Answer

c# Adjust In-Game audio 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