【发布时间】:2016-10-12 09:12:11
【问题描述】:
我遇到了脚本错误。但首先我在做什么。
我正在使我的文本变得丰富多彩,系统应该是这样的。每一秒,新的不同颜色。但是我编写了代码,它显示错误。喜欢:
错误 CS0619:
UnityEngine.Component.renderer' is obsolete:Property 渲染器已被弃用。请改用 GetComponent()。 (UnityUpgradable)'错误 CS1061:类型
UnityEngine.Component' does not contain a definition formaterial' 并且找不到扩展方法material' of typeUnityEngine.Component'(您是否缺少 using 指令或程序集引用?)
脚本也是这样的。
using UnityEngine;
using System.Collections;
public class Colors : MonoBehaviour
{
public float timer = 0.0f;
void Start()
{
}
void Update()
{
timer += Time.deltaTime;
if (timer >= 2.0f)//change the float value here to change how long it takes to switch.
{
// pick a random color
Color newColor = new Color(Random.value, Random.value, Random.value, 1.0f);
// apply it on current object's material
renderer.material.color = newColor;
timer = 0;
}
}
}
【问题讨论】:
-
error CS0619 清楚地说明了你必须做什么:使用 GetComponent
() 而不是渲染器,因为它已被弃用
标签: c# unity3d colors scripting