“图像"不包含“纹理"的定义无法找到接受“图像"类型的第一个参数的可访问扩展方法“纹理" [英] 'Image' does not contain definition for 'texture' no accessible extension method 'texture' accepting a first argument of type 'Image' could be found

查看:42
本文介绍了“图像"不包含“纹理"的定义无法找到接受“图像"类型的第一个参数的可访问扩展方法“纹理"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

This error is constantly popping in Unity after I imported a project.

这是代码:

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;
    }
}   

错误是:

Assets\Scripts\iTween.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 包自上而下的 AI";在 Unity 资产商店.

I actually found this because I was messing with the same package today. It's from an old free AI package "Top Down AI" on the Unity asset store.

解决办法:如果您只是想让它在没有编译错误的情况下运行,您需要做的就是检查并注释掉所有与 CameraFade 相关的行.没有它,示例游戏运行良好.

Solution: If you're just wanting to get it to run without the compile errors, all you need to do is go through and comment out all of the lines that have to do with the CameraFade. The example game runs fine without it.

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

If you're still wanting to fix it, then maybe someone else will be able to tell you something with what I've added below. Although, there are much simpler ways to do a camera fade now.

这似乎是为了在玩家死亡时创建一个相机淡入淡出的颜色.有几千行,所以我还没弄明白.

It appears that this was meant to create a camera fade to a color when the player dies. It's several thousand lines long, so I haven't got it all figured out yet.

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

It first creates a colored texture:

    /// <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);        
    }

...中间有很多其他不相关的代码,然后通向另一个人发布的函数:

...lots of other unrelated code in between, then leads up to the function that the other person posted:

/// <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;
    }
}

...我在这里剪了一些...

... I cut some more out here ...

/// <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;
    }
}

这篇关于“图像"不包含“纹理"的定义无法找到接受“图像"类型的第一个参数的可访问扩展方法“纹理"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆