I’m trying to add a .png texture to a mesh at runtime with the following code, but when I run the code, no colors/textures are added and a window pops up in the bottom of the inspector window showing a blank ball called “No Name (Instance)”. What could I be doing wrong, and how can I correctly add this .png to the mesh so that it has colors?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AddTexture : MonoBehaviour
{
Texture t;
string pngPath = "Materials/color3";
Renderer objRend;
// Start is called before the first frame update
void Awake()
{
}
// Update is called once per frame
void Update()
{
objRend = this.GetComponent<Renderer>();
t = Resources.Load<Texture>("pngPath");
objRend.material.mainTexture = t;
}
}