Unity运行项目时出现error CS1061错误:
error CS1061: Type `UnityEngine.Component' does not contain a definition for `pitch' and no extension method `pitch' of type `UnityEngine.Component' could be found. Are you missing an assembly reference?
“Component”未包含“pitch”的定义,并且找不到可接受第一个“Component”类型参数的扩展方法“pitch”。是否缺少using指令或程序集引用?
双击错误,用VS打开代码,找到错误:
audio.pitch = Mathf.Abs(EngineRPM / MaxEngineRPM) + 0.75f ;
if ( audio.pitch > 2.0f ) {
audio.pitch = 2.0f;
}
将audio.pitch改成:GetComponent<AudioSource>().pitch即可。