unity3d 5.0中Renderer后面没有了material

来源:互联网 发布:网络兼职什么项目最好 编辑:程序博客网 时间:2024/04/28 17:16

在unity3d5.0中 renderer后面不能使用material

需要通过GetComponent来获取组件

GameObject objcub = GameObject.CreatePrimitive(PrimitiveType.Cube);objcub.AddComponent<Rigidbody>();objcub.name = "Cube";//设置color 使用这个来获取materialobjcub.GetComponent<Renderer>().material.color = Color.blue;

我们看下material API的源码

using UnityEngine;using System.Collections;public class ExampleClass : MonoBehaviour{    public Color colorStart = Color.red;    public Color colorEnd = Color.green;    public float duration = 1.0F;    public Renderer rend;    void Start()    {        //获取renderer组件        rend = GetComponent<Renderer>();    }    void Update()    {        float lerp = Mathf.PingPong(Time.time, duration) / duration;        //这里就可以使用material来设置颜色了        rend.material.color = Color.Lerp(colorStart, colorEnd, lerp);    }}


1 0
原创粉丝点击