Unity3D,我怎么重复背景图片?

时间:2014-08-09 15:15:25

标签: unity3d

我尝试在GUILayout上重复背景图像。 从网站搜索后,无法找到如何重复图像。

可以告诉我为什么?或者我如何使windows背景图像能够自动填充?

下面是我的代码。

Texture2D LzIMGBackground;
    LzIMGBackground = Resources.LoadAssetAtPath("Assets/Textures/UI/Resources/metal-background-texture.jpg",typeof(Texture2D)) as Texture2D;
    GUILayout.BeginVertical (LzIMGBackground, "box");
    GUILayout.BeginVertical ("box");
    if(GUILayout.Button("Single Player",GUILayout.Width(200))){
        Application.LoadLevel("testGUITransitions");
    }
    GUILayout.EndVertical ();

    GUILayout.BeginVertical ("box");
    if(GUILayout.Button("Quit",GUILayout.Width(200))){
        Application.Quit();
    }
    GUILayout.EndVertical ();
    GUILayout.EndVertical ();

我已经附加了该文件。非常感谢。

Sample Image

1 个答案:

答案 0 :(得分:3)

this开始,您需要使用' GUI.DrawTextureWithTexCoords'功能

var panelWidth = ...; 
var panelHeight = ...;
yourTexture.wrapMode = TextureWrapMode.Repeat;

GUI.DrawTextureWithTexCoords(panelPos, yourTexture, 
    new Rect(0, 0, screenBounds.width / yourTexture.width, panelHeight / yourTexture.height));