'Image'不包含定义'texture'找不到接受类型'Image'的第一个参数'texture'可访问的扩展方法



导入项目后,Unity中不断出现此错误。

这是代码:

public static GameObject CameraFadeAdd(){
if(cameraFade){
return null;
}else{          
//establish colorFade object:
cameraFade = new GameObject("iTween Camera Fade");
cameraFade.transform.position= new Vector3(.5f,.5f,Defaults.cameraFadeDepth);
cameraFade.AddComponent<Image>();
cameraFade.GetComponent<Image>().texture=CameraTexture(Color.black);    // line 6081
cameraFade.GetComponent<Image>().color = new Color(.5f,.5f,.5f,0);
return cameraFade;
}
}   

错误为:

AssetsScriptsiTween.cs(6081,37): error CS1061: 'Image' does not contain a definition for 'texture' and no accessible extension method 'texture' accepting a first argument of type 'Image' could be found (are you missing a using directive or an assembly reference?)

我发现这个是因为我今天处理了同一个包。它来自一个旧的免费人工智能软件包";自上而下AI";在Unity资产商店。

解决方案:如果你只是想让它在没有编译错误的情况下运行,你所需要做的就是浏览并注释掉所有与CameraFade有关的行。没有它,示例游戏运行良好。

如果你仍然想修复它,那么也许其他人可以用我在下面添加的内容告诉你一些事情。不过,现在有更简单的方法来进行相机淡入淡出。

这似乎是为了在玩家死亡时创建一个渐变色的相机。它有几千行,所以我还没有弄清楚。

它首先创建一个彩色纹理:

/// <summary>
/// Creates and returns a full-screen Texture2D for use with CameraFade.
/// </summary>
/// <returns>
/// Texture2D
/// </returns>
/// <param name='color'>
/// Color
/// </param>
public static Texture2D CameraTexture(Color color){
Texture2D texture = new Texture2D(Screen.width,Screen.height,TextureFormat.ARGB32, false);
Color[] colors = new Color[Screen.width*Screen.height];
for (int i = 0; i < colors.Length; i++) {
colors[i]=color;
}
texture.SetPixels(colors);
texture.Apply();
return(texture);        
}

中间有很多其他不相关的代码,然后导致另一个人发布的功能:

/// <summary>
/// Changes a camera fade's texture.
/// </summary>
/// <param name='texture'>
/// A <see cref="Texture2D"/>
/// </param>
public static void CameraFadeSwap(Texture2D texture){
if(cameraFade){
cameraFade.GetComponent<Image>().texture=texture;
}
}

我在这里切了一些。。。

/// <summary>
/// Creates a GameObject (if it doesn't exist) at the default depth that can be used to simulate a camera fade.
/// </summary>
/// <param name='texture'>
/// A <see cref="Texture2D"/>
/// </param>
/// <returns>
/// A <see cref="GameObject"/> for a reference to the CameraFade.
/// </returns>
public static GameObject CameraFadeAdd(Texture2D texture){
if(cameraFade){
return null;
}else{          
//establish colorFade object:
cameraFade = new GameObject("iTween Camera Fade");
cameraFade.transform.position= new Vector3(.5f,.5f,Defaults.cameraFadeDepth);
cameraFade.AddComponent<Image>();
cameraFade.GetComponent<Image>().texture=texture;
cameraFade.GetComponent<Image>().color = new Color(.5f,.5f,.5f,0);
return cameraFade;
}
}
/// <summary>
/// Creates a GameObject (if it doesn't exist) at the default depth filled with black that can be used to simulate a camera fade.
/// </summary>
/// <returns>
/// A <see cref="GameObject"/> for a reference to the CameraFade.
/// </returns>
public static GameObject CameraFadeAdd(){
if(cameraFade){
return null;
}else{          
//establish colorFade object:
cameraFade = new GameObject("iTween Camera Fade");
cameraFade.transform.position= new Vector3(.5f,.5f,Defaults.cameraFadeDepth);
cameraFade.AddComponent<Image>();
cameraFade.GetComponent<Image>().texture=CameraTexture(Color.black);
cameraFade.GetComponent<Image>().color = new Color(.5f,.5f,.5f,0);
return cameraFade;
}
}

相关内容

  • 没有找到相关文章