Reputation: 53
I'm just starting in game development and I'm working in Unity, 2d. I worked through a tutorial to make a simple mesh, in order to make a field of vision of the player and npcs. All of my code and unity setup is the same as the tutorial, but the mesh either isn't rendering or is straight up invisible. Here is my code.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerFOV : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
Mesh mesh = new Mesh();
GetComponent<MeshFilter>().mesh = mesh;
Vector3[] vertices = new Vector3[3];
Vector2[] uv = new Vector2[3];
int[] triangles = new int[3];
vertices[0] = Vector3.zero;
vertices[1] = new Vector3(50, 0);
vertices[2] = new Vector3(0, -50);
triangles[0] = 0;
triangles[1] = 1;
triangles[2] = 2;
mesh.vertices = vertices;
mesh.uv = uv;
mesh.triangles = triangles;
}
// Update is called once per frame
void Update()
{
}
}
Upvotes: 0
Views: 45