Switching mesh through Mesh Filter C#

Hi, I’m new to coding, sorry if this is a rudimentary question but I’ve been having trouble figuring it out based on similar questions I’ve seen. Be harsh, don’t feel shy about telling me where I screwed up. I’m a 3D artist, this is all a new language to me.

I’m building a basic gallery to showcase a few different meshes and I want to build in the ability to switch to a specific mesh from my Assets on a button press while keeping the materials the same. I’m thinking that it’s possible to do in C# through the Mesh Filter, but I’m not having any luck.

Here is the code I’ve cobbled together so far. Any help is hugely appreciated.

using UnityEngine;
using System.Collections;

public class MeshSelect : MonoBehaviour {
	
	void Start () {
	
	}

	void Update () 
	{
		if (Input.GetKeyDown (KeyCode.Keypad3)) 
		{
			gameObject.GetComponent<MeshFilter>().mesh = Resources.Load("<Mapped/DAFO3");
		}
	
	}
}

Hello dude.

Because you are an artist I won’t give you precise technical details.
When using Resources.Load, give a valid path relative to any Resources folders.
In your case replace your line 14 by:

gameObject.GetComponent<MeshFilter>().mesh = Resources.Load<Mesh>("Mapped/DAFO3");

It should work.

I came up with a pretty inelegant solution, don’t know if anyone has any insight into how I could refine it. I’ve attached all the meshes to an empty parent GameObject, then attached a script that enables them on a keypress and disables the other meshes. It’s not perfect, and I have a slightly different code for each one. Is there a way to refine this code to something that can be applied across all the meshes? It’s only a few lines, and it works, but it seems like a messy way of doing things.

using UnityEngine;
using System.Collections;

public class SelectDAFO4 : MonoBehaviour {
	public Renderer rend;
	
	void Start () {
		rend = GetComponent<Renderer> ();
	}
	
	void Update () 
	{
		//button to enable mesh
		if (Input.GetKeyDown (KeyCode.Keypad4)) {
			rend.enabled = true;
		} 
		//All other buttons to disable mesh
		else if (Input.GetKeyDown (KeyCode.Keypad3)) {
			rend.enabled = false;
		} 
		else if (Input.GetKeyDown (KeyCode.Keypad5)) {
			rend.enabled = false;
		} 
	}
}