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 JerryCic · Dec 22, 2011 at 01:22 AM · texturematerialbitmap

How to i split a bitmap into parts? And use each part for a texture?

I am new!

I am creating a simple slider puzzle as a programming excersise. I have successfully created 15 cubes at runtime and stacked them into a 4x4 on the XY plane. I have a bitmap image 1024 by 1024 in my assets as a material whose scale is 1,1,1. Each cube is 1,1,1 as well. I want to paint the cooresponding part of the image onto each cube as they are instantiated in the camera's startup routine.

Any Ideas?

Thanx!

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by flamy · Dec 22, 2011 at 04:25 AM

You have to unwrap all fifteen cubes in maya and make it share the same texture!! that is the easiest!.. If u want to follow this search for unwraping in google u will get.

If you want to do it in unity u have set the UVs manually by using Material.textureOffset and Material.textureScale

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
1

Answer by JerryCic · Dec 22, 2011 at 10:09 PM

For the sake of others who find this thread.

To divide a square image into 16 parts (4wide by 4high) i did this:

using UnityEngine; using System.Collections;

public class InitCube : MonoBehaviour {

 public GameObject ga;
 float wide; // tiles wide
 float high; // tiles high

 // Use this for initialization
 void Start () {
     float x;
     float y;
     x = ga.transform.position.x;
     y = ga.transform.position.y;
     wide = 4;
     high = 4;
     float scx=-(1/wide);
     float scy=-(1/high);
     float offx=-(wide-1-x)/wide;
     float offy=-(high-1-y)/high;
     ga.renderer.material.SetTextureScale("_MainTex", new Vector2(scx,scy));
     ga.renderer.material.SetTextureOffset("_MainTex", new Vector2(offx, offy));  
 }

}

Notice:

 Think of a brick wall 4 bricks tall by 4 bricks wide.
 Think of one graphic covering all 16 bricks such that the image is intact accross the entire wall.
 Each brick gets a part of the image.
 The GameObject is a cube whose scale is 1,1,1
 The graphic is already a material on the cube surface.
 position x=0,y=0 is the lower left corner of the structure
 position 3,3 is the upper right brick.
 In Unity, the material has a "Tileing" and an "Offset" properties.
 In the c# code the SetTextureScale actually changes the "Tileing" property.

There you have it.

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 JoeriVDE · Jul 12, 2016 at 05:43 PM 0
Share

@JerryCic that's genius! Can't say thank you enough!

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

6 People are following this question.

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

Related Questions

Would a color based game run better than a texture based game? 2 Answers

Attaching scripts to meshes with multiple materials 2 Answers

Quality loss on texture 1 Answer

How do I get a material to tile dynamically? 1 Answer

Using Rpg maker XP Tiles (2D Tile System) 2 Answers


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