Skip to content

Instantly share code, notes, and snippets.

@PrashantUnity
Last active August 13, 2022 05:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PrashantUnity/fa1cb602e5ac98a544a063731420ba24 to your computer and use it in GitHub Desktop.
Save PrashantUnity/fa1cb602e5ac98a544a063731420ba24 to your computer and use it in GitHub Desktop.
Dynamically Change Materials
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class DeerScript : MonoBehaviour
{
// this is gameobject whose material will be changed
public GameObject target;
// this is array of materials
// which is assigned in inspector
public Material[] materials;
// in this example i have used trigger
private void OnTriggerEnter(Collider other)
{
// this the type of mesh rendering used in gameobject
// your may be different like MeshRenderer
// you can find in inspector of target
target.GetComponent<SkinnedMeshRenderer>().materials = materials;
}
}
// here is demo of that example but it slightly differs from the above
// instead of array pre assigned i have used aonther way around
// if this help please subscribe my youtube channel
// https://youtu.be/XY6XiLEh4II
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment