Hello. I am a new programmer and i want your help. I am working a project where i try to select and spawn a primitive mesh in scene via a dropdown button. I never use something like that so if anyone can help me. I have made an array wich i include my primitives meshes and i want to select them when i select the dropdown options. Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class ChangeMeshFilter : MonoBehaviour
{
public Mesh myMesh= new Mesh[5];
private int a = 0;
private GameObject gObject;
public Dropdown MeshSelector;
void Start ()
{
CreateObject();
}
void CreateObject() {
gObject = new GameObject();
gObject.AddComponent<MeshFilter>().mesh = myMesh[0] ;
gObject.AddComponent<MeshRenderer>();
gObject.GetComponent<MeshRenderer>().material.color = Color.green;
}
public void Changer()
{
if (a < 4)
{
a = a + 1;
}
else
{
a = 0;
}
gObject.GetComponent<MeshFilter>().mesh = myMesh[a];
}