- Home /
Image to 3D level
Hi: I was wondering if i would be able to take a image into unity like a height map and instead using each individual pixel based on color to spawn a 3D prefab in scene in the editor. no run time needed. I remember seeing a tutorial about it and I can not seem to find anything due to the new tilemaps in 2D taking all the google searches. Thanks: James
Answer by RadonRaph · Dec 02, 2019 at 10:42 PM
Hello @jimjames, Just some tips here not real answer, To instanstiate a level based on texture just loop for each pixels using
Color c = myText.GetPixel(x,y)
and then spawning something depending of the color.
To make it editor only just put "[ExecuteAlways]" just before your class and then make a custom editor like this
 [CustomEditor(typeof(MyScript))]
 public class MyEditor : Editor
 {
 
     MyScript comp;
 
     public void OnEnable()
     {
         comp = (MyScript)target;
     }
 
     public override void OnInspectorGUI()
     {
              
         bool GenerateWorld =  GUILayout.Button("Generate World");
         if (GenerateWorld)
         {
             comp.Generate();
         }
      }
 }
If you want to build an real world (terrain like) with an heightmap i suggest you to search at "Mesh from heighmap".
If you want an more precise answer please provide more information about what you trying to do :)
I hope that will help you,
Raph
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                