一个好玩的小动态, 一个小滑块, 与另一个固定块撞击后连续变色, 简单而有说服力
using UnityEngine;
using System.Collections;
// 改变材制动
public class ouyChangMt : MonoBehaviour {
public Material[] material;
Renderer rend;
// Use this for initialization
void Start () {
rend = GetComponent<Renderer> ();
rend.enabled = true;
rend.sharedMaterial = material [0];
}
void OnCollisionEnter(Collision col)
{
if (col.gameObject.tag == "Box") {
rend.sharedMaterial = material [1];
} else {
rend.sharedMaterial = material [2];
}
}
// Update is called once per frame
void Update () {
}
}