如何在统一中使用GUITexture

时间:2015-07-05 14:42:47

标签: unity3d

我是团结的新手。我在脚本中看过GUITexture,并且不知道如何使用它。我想知道如何使用GUITexture以及如何在屏幕上显示GUITexture。请帮帮我。

1 个答案:

答案 0 :(得分:0)

GUI(图形用户界面)纹理,是可以在屏幕上显示的图像,就像在相机上添加图层一样。我的意思是,如果你在屏幕上放置一个GUI纹理,无论玩家去哪里,它总是出现在相对于玩家相机的相同位置。使用GUI纹理的一个很好的例子是,如果你想创建一个始终显示在玩家视角的健康栏。

如何使用GUI纹理:

public class TestGUI {
     //declare a texture, you can do this multiple ways
     public Texture textureType1;
     //this type is usually more blurry because it is being rendered as a texture rather than a plain image
     public 2DTexture textureTyple2;
     //this type is less blurry than Texture, and is used for 2D elements
     public GUITexture textureType3;
     //this type is the clearest and is meant solely for GUI

     public void OnGUI()
     {
          GUI.DrawTexture(new Rect(xOffset, yOffset, width, height), textureType3);
          //This texture is drawn but will not necessarily fill the rectangle you declared
          GUI.DrawTexture(new Rect(xOffset, yOffset, width, height), textureType3, ScaleMode.ScaleToFit, true, 1.0f);
          //this texture is drawn and will be scaled to fill the dimensions of the rectangle you declared with a fill aspect ratio of 1.
          //this is good for things like health bars since it doesnt matter if the image is stretched since it will most likely only be a color
     }
}