Hi all guys!
I’ve a problem: I put a mesh (a plan) made with only two triangles, in front of my main camera. This mesh has a texture and this texture becomes totally black if I build my scene for android.
If I apply the same texture on a cube it works.
I tried all I read on this forum:
- Resized the texture
- Changed the material to “mobile”
- Tried every type of textures compression
But nothing.
Here’s the code that generate my mesh:
using UnityEngine;
using System.Collections;
/// <summary>
/// Represents a quad, a square composed by two primitives.
/// </summary>
[RequireComponent(typeof(MeshFilter), typeof(MeshRenderer))]
public class Quad : MonoBehaviour {
// Uses always the same vertices. The transform component automatically shifts the quad
// to its proper location in 3D space.
private static readonly Vector3[] vertices = {
new Vector3(-0.5f, 0.5f, 1), new Vector3(0.5f, 0.5f, 0), new Vector3(0.5f, -0.5f, 0), new Vector3(-0.5f, -0.5f, 0)
};
// The indices are always the same.
private static readonly int[] indices = {
0, 1, 2, 2, 3, 0
};
// Contains the UV coordinates of each quad vertex. The array is indexed by Corner enum, properly cast to int.
private Vector2[] uvCoordinates;
// Reference to the mesh component.
private Mesh mesh;
/// <summary>
/// The material to use when drawing this quad. Mainly exploited for its texture.
/// </summary>
public Material material;
public Vector2 upperLeftUv, upperRightUv, lowerRightUv, lowerLeftUv;
/// <summary>
/// Gets or sets the UV coordinate of the given corner.
/// </summary>
public Vector2 this[Corner corner] {
get {
return uvCoordinates[(int)corner];
}
set {
uvCoordinates[(int)corner] = value;
}
}
/// <summary>
/// Initializes the quad.
/// </summary>
public Quad() {
this.upperLeftUv = new Vector2(0, 1);
this.upperRightUv = new Vector2(1, 1);
this.lowerRightUv = new Vector2(1, 0);
this.lowerLeftUv = new Vector2(0, 0);
}
// Creates a new mesh and assigns vertices and triangles.
void Awake() {
this.uvCoordinates = new Vector2[] { upperLeftUv, upperRightUv, lowerRightUv, lowerLeftUv };
this.mesh = new Mesh();
this.mesh.vertices = vertices;
this.mesh.triangles = indices;
this.mesh.uv = this.uvCoordinates;
}
// Assign the new mesh to the mesh drawer property and the given material to its renderer.
void Start() {
this.GetComponent<MeshFilter>().mesh = mesh;
this.GetComponent<MeshRenderer>().material = material;
}
}