I'm using Unity 2018 and its really confusing me. I generate a plane mesh in code and when it comes to positioning (transform.position.x) it on the X axis I can't understand why moving it further to the right the X value decreases (into the negatives) and the X value increases to the left??
The Y axis works as expected, up increases the value (positive), down decreases (negative). The Z axis, away from camera = negative and towards = positive.
(Just creating a basic 3D cube game object using the Unity Create tool, the same issue applies.)
I need to figure if this is how Unity is set up now? Or I'm doing something wrong.. But I'm stuck on this!!
//create mesh code:
Mesh CreateMesh(float width, float height)
{
Mesh m = new Mesh();
m.name = "ScriptedMesh";
m.vertices = new Vector3[] {
new Vector3(0, 0, 0.01f),
new Vector3(width, 0, 0.01f),
new Vector3(width, height, 0.01f),
new Vector3(0, height, 0.01f)
};
m.uv = new Vector2[] {
new Vector2 (0, 0),
new Vector2 (0, 1),
new Vector2(1, 1),
new Vector2 (1, 0)
};
m.triangles = new int[] { 0, 1, 2, 0, 2, 3 };
m.RecalculateNormals();
return m;
}
//build our first wall mesh obj
var wallObj = new GameObject("Wall-" + wallc.WallLengthCM + " (" + wallIndex + ")");
var _wallMesh = (MeshFilter)wallObj.AddComponent(typeof(MeshFilter));
_wallMesh.mesh = CreateMesh((float)wallc.WallLengthCM, (float)wallc.WallHeightCM);
MeshRenderer wallRenderer = wallObj.AddComponent(typeof(MeshRenderer)) as MeshRenderer;
wallRenderer.material = ShedWallMat;
var wallMesh = Instantiate(_wallMesh,
new Vector3 { x = 0, y = ((float)wallc.WallHeightCM * 2 * wallIndex) + vertSpace, z = 0 },
new Quaternion { w = 0, x = 0, y = 0, z = 0 });