It success in (unity ver. 4.7 / monodevelop) but not in (unity ver. 2017 / visual studio)
The error is Line 25 [1] & Line 129 [2] .
Thanks.
using UnityEngine;
using System.Collections;
// ----------------------------------------------------------------------------
// Create a MeshCollider that is used to detect collisions of search lasers.
// ----------------------------------------------------------------------------
public class ScoutingLaserMeshController : MonoBehaviour
{
private Mesh mesh;
private MeshFilter meshFilter;
private MeshCollider meshCollider;
private ScoutingLaser scoutingLaser;
private static float PIECE_ANGLE = 5.0f; // Angle of 1 polygon (smooth circle).
private static float FAN_RADIUS = 10.0f; // radius of circle
void Start()
{
mesh = new Mesh();
meshFilter = GetComponent<MeshFilter>();
meshCollider = GetComponent<MeshCollider>();
meshCollider.mesh = mesh; // [1] error occurs here!!!!! error CS1061: Type `UnityEngine.MeshCollider' does not contain a definition for `mesh' and no extension method `mesh' of type `UnityEngine.MeshCollider' could be found. Are you missing an assembly reference?
// .
scoutingLaser = GameObject.FindGameObjectWithTag("ScoutingLaser").GetComponent<ScoutingLaser>();
}
void Update()
{
}
public void clearShape()
{
mesh.Clear();
meshFilter.mesh = mesh;
// After changing the mesh, it is not reflected unless set to false -> true.
meshCollider.enabled = false;
meshCollider.enabled = true;
}
public void makeFanShape(float[] angle)
{
float startAngle; // start angle of circle
float endAngle; // End angle of circle
float pieceAngle = PIECE_ANGLE; // Angle of 1 polygon (smooth circle).
float radius = FAN_RADIUS; // radius of circle
startAngle = angle[0];
endAngle = angle[1];
// --------------------------------------------------------------------
// Ready
// --------------------------------------------------------------------
if (Mathf.Abs(startAngle - endAngle) > 180f)
{
// 0 degrees <-> +360 degrees is considered as exceeding 359 degrees.
if (startAngle < 180f)
{
startAngle += 360f;
}
if (endAngle < 180f)
{
endAngle += 360f;
}
}
Vector3[] circleVertices; // The item coordinates of each polygon that makes up the circle.
int[] circleTriangles; // Polygon face information (vertex connection information)
// The angle should be start < end.
if (startAngle > endAngle)
{
float tmp = startAngle;
startAngle = endAngle;
endAngle = tmp;
}
// number of triangles.
int triangleNum = (int)Mathf.Ceil((endAngle - startAngle) / pieceAngle);
// secure the array
circleVertices = new Vector3[triangleNum + 1 + 1];
circleTriangles = new int[triangleNum * 3];
// --------------------------------------------------------------------
// create polygon
// --------------------------------------------------------------------
// vertex
circleVertices[0] = Vector3.zero;
for (int i = 0; i < triangleNum + 1; i++)
{
float currentAngle = startAngle + (float)i * pieceAngle;
// so as not to exceed the final value
currentAngle = Mathf.Min(currentAngle, endAngle);
circleVertices[1 + i] = Quaternion.AngleAxis(currentAngle, Vector3.up) * Vector3.forward * radius;
}
// index
for (int i = 0; i < triangleNum; i++)
{
circleTriangles[i * 3 + 0] = 0;
circleTriangles[i * 3 + 1] = i + 1;
circleTriangles[i * 3 + 2] = i + 2;
}
// --------------------------------------------------------------------
// mesh creation
// --------------------------------------------------------------------
mesh.Clear();
mesh.vertices = circleVertices;
mesh.triangles = circleTriangles;
mesh.Optimize(); // [2] error occurs here!! error CS0619: `UnityEngine.Mesh.Optimize()' is obsolete: `This method is no longer supported (UnityUpgradable)'
mesh.RecalculateBounds();
mesh.RecalculateNormals();
meshFilter.mesh = mesh;
// After changing the mesh, it is not reflected unless set to false -> true.
meshCollider.enabled = false;
meshCollider.enabled = true;
}
void OnTriggerEnter(Collider collider)
{
scoutingLaser.Lockon(collider);
}
void OnTriggerExit()
{
}
void OnTriggerStay(Collider collider)
{
}
}