嗨我腳本有一些錯誤。也許你可以幫忙。噢......Unity中的C#錯誤
我想讓我的文字變得豐富多彩,每一秒都有新的不同顏色。但是當我編寫腳本時就會出現這樣的錯誤。你可以幫幫我嗎 ? 它給了Unity中的錯誤。
錯誤CS0619:
UnityEngine.Component.renderer' is obsolete:
物業渲染器已被棄用。改用GetComponent()。 (UnityUpgradable) '錯誤CS1061:
UnityEngine.Component' does not contain a definition for
材料類型',沒有擴展方法material' of type
UnityEngine.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;
}
}
}
錯誤CS0619明確規定你必須做的:用GetComponent(),而不是渲染器,因爲它已被棄用 –
TheDjentleman