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 DyrdaOrg · Oct 07, 2013 at 07:32 AM · c#texturescustomaddingcubes

How to put specific shapes/textures instead of generating colors (C#)

Hello,

My problem is that I'm making pentomino-like game and I'm generating shapes from matrixes. Code works well, etc. But my problem is to add textures to them (2D plant-shape like figures). Is there any method to hardcode them or is this just wrong from the beginning and I should start with different approach and models of that pentominos?

Right now:

     public void InitBlockTextures(int w, int h) //initializing block textures
     {
         green_texture = new Texture2D(w, h);
         ...
         black_texture = new Texture2D(w, h);
         CreateBeveledTexture(green_texture, 0, 1, 0);
         ...
         CreateBeveledTexture(black_texture, 0, 0, 0);
     }
 
     public Texture2D GetBlockTexture(int color) //for each color we're getting texture
     {
         if(color==1)return green_texture;
         ...
         if(color==8)return black_texture;
         return null;
     }

I used matrixes and colors generated that way cause it was pretty simple to program rotating options for something like this:

 public class PentominoPieces //here we have pieces
 {
 ...
     int[,] P8R1 = new int[4,4]    {
         {1,1,0,0},
         {0,1,1,0},
         {0,0,1,0},
         {0,0,0,0}
     };
 ...
 }

 public int[,] GetTetrisPieceBitmask(int type, int rotation) //each rotation has specified bitmask
 {
     ...
     if(type==8)
     {
         if(rotation==1)return P8R1;
         if(rotation==2)return P8R2;
         if(rotation==3)return P8R3;
         if(rotation==4)return P8R4;
     }

 

But now it not looks that easy anymore and I'll be thankful for every help.

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 DyrdaOrg · Oct 07, 2013 at 03:41 PM 0
Share

I know that I look like total n00b (and it's not far from there), but actually I answered much more qusetions than I asked (http://answers.unity3d.com/users/24865/mcdardy.html <- it's not my fault that I can't log in on that account) so I'll be glad if one of Great $$anonymous$$asters of Coding help me a little - pretty please :)

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by GwenoleGerard · Oct 08, 2013 at 07:46 AM

I'm not sure what you want to do (my english are very bad) but if you use a texture you create in script, you can use Texture2D.SetPixel, Texture2D.SetPixels and Texture2D.Apply to change with code your Texture, like said here

Edit: to load your own Texture, you can use Ressources.Load and do something like that:

 Texture2D myTexture = Ressources.Load("YourPath/YourTextureName") as Texture2D

The example in the link show how apply directly the Texture on object's material and said "The path is relative to any Resources folder inside the Assets".

Hope it could help

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 DyrdaOrg · Oct 08, 2013 at 08:43 AM 0
Share

Thank you, thank you, thank you for your answer, and don't worry bout your english - my isn't perfect also. I try to explain better:

What I have:

http://3.bp.blogspot.com/-PeL$$anonymous$$clZA4N4/T-pzZfghReI/AAAAAAAANuk/8GmuS1Q$$anonymous$$vmo/s1600/PCP294_theory_figure2.jpg

What I need:

https://lh6.ggpht.com/nu6Ffy1nfV77dapIYOnY6UJ5SQJ1Lxb0zRsRy$$anonymous$$rlUdz9YZrol8m3GrrAzsl7vTHQJwbC=w300 (not snakes though, but you can get the idea)

$$anonymous$$y prototype is working and is flawless, but I need to add those "custom plants shape like" textures and I don't know if I made the right approach... Any way to "hardcode" them (choosing from $$anonymous$$yProjectDirectory my png/gif) and bind to my shapes?

Thanks once again for your time

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

17 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Stirching textures together to make another one 0 Answers

Flip over an object (smooth transition) 3 Answers

Making a bubble level (not a game but work tool) 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