void MakeMeshData() { GameObject player = GameObject.Find("Player"); ArrowMesh arrowMesh = player.GetComponent <ArrowMesh>(); vertices = new Vector3[] { new Vector3(-1f * arrowMesh.width / 2f, 0f, 0f), new Vector3(arrowMesh.width / 2f, 0f, 0f), new Vector3(0f, arrowMesh.totalHeight - arrowMesh.topHeight, 0f), new Vector3(0f, arrowMesh.totalHeight - arrowMesh.topHeight - height, 0f), }; triangles = new int[] { 0, 2, 3, 2, 1, 3 }; }
void CreateArrow(Vector2 startPos, Vector2 endPos, Color col) { GameObject meshHolder = new GameObject("Arrow"); meshHolder.layer = LayerMask.NameToLayer("Arrows"); meshHolder.transform.parent = transform; var renderer = meshHolder.AddComponent <MeshRenderer> (); var filter = meshHolder.AddComponent <MeshFilter> (); renderer.material = material; renderer.material.color = col; meshHolder.transform.position = new Vector3(0, 0, -1 - activeArrows.Count * 0.1f); var mesh = new Mesh(); filter.mesh = mesh; ArrowMesh.CreateArrowMesh(ref mesh, startPos, endPos, lineWidth, headSize); activeArrows.Add(meshHolder.transform); }
/// Draw a 2D arrow (on xy plane) void DrawArrow2D(Vector2 start, Vector2 end, float lineWidth, float headSize, Color color, bool flatHead = true, float zPos = 0) { if (arrowIndex >= arrowObjects.Count) { GameObject arrowObject = new GameObject("Arrow"); arrowObject.transform.parent = transform; var renderer = arrowObject.AddComponent <MeshRenderer> (); var filter = arrowObject.AddComponent <MeshFilter> (); renderer.material = arrowMaterial; filter.mesh = new Mesh(); arrowObjects.Add(arrowObject); } arrowObjects[arrowIndex].transform.position = new Vector3(0, 0, zPos); arrowObjects[arrowIndex].SetActive(true); arrowObjects[arrowIndex].GetComponent <MeshRenderer> ().material.color = color; Mesh mesh = arrowObjects[arrowIndex].GetComponent <MeshFilter> ().mesh; ArrowMesh.CreateArrowMesh(ref mesh, start, end, lineWidth, headSize, flatHead); arrowIndex++; }