- Home /
Char To Texture
I have one major issue in applying texture on object with respect to char. For e.g.: I have array of char[] which has like "R" "E" "D" of string "RED". so, with respect to this i want to apply these texture on single object each like on quad. Quad 1 has "R" of char[0] texture Quad 2 - "E" of char[1] and Quad - "D" char[2].
@ Graham appreciate your concern, but i got the complete solution below.
Answer by shriya · Jul 31, 2015 at 11:06 AM
HI Suzit,
If I have understood correctly then the solution is mentioned below. Keep your Textures in Resources Folder and name your texture as per alphabet it contains (see attachment). This script is basically instantiating cubes equal to the length of your character array and applying texture to it..Output is also shown! For any clarification feel free to ask . Hope it helps.
using UnityEngine;
using System.Collections;
public class ApplyTexture : MonoBehaviour {
private char[] charac={'R','E','D'};
public GameObject cube;
// Use this for initialization
void Start ()
{
for (int i = 0; i<charac.Length; i++)
{
GameObject x = Instantiate(cube,new Vector3(i*2,0,0),Quaternion.identity) as GameObject;
Texture gettexture = Resources.Load (charac[i].ToString()) as Texture;
x.GetComponent<Renderer>().material.mainTexture =gettexture;
}
}
}
[1]: /storage/temp/51333-screen-shot-2015-07-31-at-42736-pm.png
[2]: /storage/temp/51334-screen-shot-2015-07-31-at-42955-pm.png
Your answer
Follow this Question
Related Questions
can I apply my camera photo image to unity model face? 0 Answers
Unnatural Texture Stretching 1 Answer
Assigning UV Map to model at runtime 0 Answers
Gray line at top of the texture 0 Answers
Texture blending 0 Answers