I have a square gameobject with a script attached to it in my scene.
This gameobject already has a material component called matOne attached to it.
When it’s hit by an object, I need the square to change it’s material to matTwo, which is inside my project assets folder.
I have absolutely no idea on how to do this.
void OnCollisionEnter(Collision col)
{
if (brickType == BrickType.Grass)
{
brickType = BrickType.Dirt;
// Code that changes the mesh to a mesh in my assets.
hitPoints = hitPoints - takeDamage;
hitPoints = hitPoints - 1;
}
}
My guess is that I need to use:
gameObject.GetComponent<MeshRenderer>().material //some more code
and
Resources.Load //some more code
But that’s all I managed to extract from various other questions and the official documentation.