Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSHARP

unity change material

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 renderin 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 is have used aonther way around
// demo is in the link
// if this help please subscribe my youtube channel
// https://youtu.be/XY6XiLEh4II
Source by youtu.be #
 
PREVIOUS NEXT
Tagged: #unity #change #material
ADD COMMENT
Topic
Name
5+1 =