- Home /
Trying to make my own plane using only 2 triangles?
So unity provides gameobject creation of a plane which contains a lot of triangles in which Unity calculates which is really unneeded for a simple plane. I was following a tutorial on how to do this, but I am getting an error.
Optimized Plane script:
#pragma strict
class OptPlane extends Editor{
@MenuItem("GameObject/Create Other/Opt Plane")
static function Init (){
var customPlane : GameObject = new GameObject("Optimized Plane");
var meshFilter : MeshFilter = customPlane.AddComponent(MeshFilter);
customPlane.AddComponent(MeshRenderer);
var destination : String = "Asset/Model/OptimizedPlane.asset";
var mesh : Mesh = AssetDatabase.LoadAssetAtPath(destination, Mesh);
if(! mesh){
mesh = Mesh();
mesh.name = 'Optimized Plane';
var vertices : Vector3[] = [Vector3(-1,0,1), Vector3(1,0,1), Vector3(1,0,-1), Vector3(-1,0,-1)];
var uv : Vector2[] = [Vector2(-1,1), Vector2(1,1), Vector2(1,-1), Vector2(-1,-1)];
var tangents : Vector4[] = [Vector4(-1,0,1,1), Vector4(1,0,1,1), Vector4(1,0,-1,1), Vector4(-1,0,-1,1)];
var triangles: int[] = [0,1,3,3,1,2];
mesh.vertices = vertices;
mesh.uv = uv;
mesh.tangents = tangents;
mesh.triangles = triangles;
mesh.RecalculateNormals();
mesh.RecalculateBounds();
mesh.Optimize();
AssetDatabase.CreateAsset(mesh, destination);
AssetDatabase.SaveAssets();
}
meshFilter.mesh = mesh;
Selection.activeObject = customPlane;
}
}
Warning: UnityException: Creating asset at path Asset/Model/OptimizedPlane.asset failed. OptPlane.Init () (at Assets/Editor/OptPlane.js:32)
I understand that it can't create it to this location I sent it, but from the tutorial he did nothing special besides create a "Model" folder and it just worked for him. Also, what is this .asset extension, I am just guessing it is what Unity uses to create objects in the scene or something.
Here is the link for reference. http://www.youtube.com/watch?feature=player_detailpage&v=ojEAHx_vY3U#t=1952s
@cdrandin just for the record. If you are trying to make essentially "2D sprites"
"2DToolkit" from the asset store is hugely popular. it would be more or less impossible or years more work to do 2D sprites in unity without it.
it utterly takes care of resizing quads as you discuss, animations, colliders, sprite atlases etc
Grab 2DTooljit and all the similar packages, and decide which one you like. Hope it helps!
Your answer
![](https://koobas.hobune.stream/wayback/20220613091010im_/https://answers.unity.com/themes/thub/images/avi.jpg)