【发布时间】:2019-01-23 04:00:55
【问题描述】:
我想在我的项目中的所有其他组件和 GUI 纹理之前绘制一个游戏对象。
我创建了第二个相机并设置了深度和图层,但它仍然无法正常工作。我希望你能帮助我找到错误或我忘记的东西。
这是我绘制简单纹理的 MainScript:
using UnityEngine;
using System.Collections;
public class MainScript : MonoBehaviour
{
Texture2D texture;
// Use this for initialization
void Start()
{
texture = new Texture2D(Screen.width, Screen.height);
for (int y = 0; y < texture.height; y++)
{
for (int x = 0; x < texture.width; x++)
{
texture.SetPixel(x, y, Color.blue);
}
}
texture.Apply();
}
void OnGUI()
{
GUI.DrawTexture(new Rect(0, 0, texture.width, texture.height), texture);
}
}
我还创建了两个摄像机和一个显示 GUI 纹理的游戏对象。纹理在预览屏幕中可见,但在运行时在 MainScript 中绘制的纹理是前景化的。
我又为我的相机对象制作了两张截图。见这里:
我还可以为您提供整个项目。这只是一个基本的测试项目。
这是 Google Drive 中项目的链接:Download
【问题讨论】: