我需要一些帮助来解决相机脚本和GUI.button菜单的问题 .

这是我的场景层次结构:

有一个相机(名为“animaCam”),可以看到5层 . 在每一层上都有一个纹理动画脚本附加到一个游戏对象(立方体),如果在gui.box(菜单)上点击了合适的gui.button,它就会播放动画 .

在这台相机之前,还有另一台相机(名为“logoCam”),用作徽标屏幕,只能看到一层 .

通过这种配置,我想实现以下功能 . 当用户点击gui.button时,会弹出一个gui.box,最初显示logoCam和五个gui.buttons可供选择 .

这些按钮中的每一个都执行以下操作(有一些误用)

一个 . 应该隐藏logoCam b . 应启用animaCam c . 应选择合适的Cube d层 . 应该在多维数据集上启动动画脚本

通过这种配置,我可以在Unity播放器和Android设备上运行应用程序,但我必须解决以下问题:

一个 . 一旦用户点击“showMenuOptions”的gui.button,在Android设备上菜单就会保持打开状态 . 即使再次点击按钮关闭它也会停留在屏幕上 . 在Unity播放器上,菜单的gui.button表现应当,点击时打开/关闭 .

湾关于用户选项,例如第一个动画,功能执行和动画播放 . 当用户单击启用/禁用“showMenuOption”的其他gui.button时,菜单会关闭,但动画会继续播放 . 它应该在关闭菜单时关闭 .

我相信,错误必须在Update函数中 . 我已经尝试了我能想到的一切,却没有取得多大成功 .

请看下面的代码 . 如果我有误,可以发布一些想法或更好的代码片段 . 我真的需要制作相机和gui.button菜单,在Unity播放器的设备上都应该表现得很好 . 提前感谢您的回答 .

这是代码片段:

//ShowAnimation Menu with camera option

#pragma strict

var native_width :  float = 480;
var native_height : float = 320;
var btnTexture : Texture;
var bgrImage : Texture; 
public var animaCam : Camera;
public var logoCam : Camera;
public var animaCamOn : boolean = false;
public var logoCamOn : boolean = false;
var showMenuOptions:boolean = false;    //true = show the other GUI elements
public var runAnima1 = false;
public var runAnima2 = false;
public var runAnima3 = false;
public var runAnima4 = false;
public var runAnima5 = false;
var animator1Mask : LayerMask; // select desired camera layer in inspector
var animator2Mask : LayerMask; // select desired camera layer in inspector
var animator3Mask : LayerMask; // select desired camera layer in inspector
var animator4Mask : LayerMask; // select desired camera layer in inspector
var animator5Mask : LayerMask; // select desired camera layer in inspector

function Awake () 
{
DontDestroyOnLoad (GameObject.FindGameObjectWithTag("animator"));
}   

function Start() 
{
    animaCam.enabled = false;
}


function Update() 
{
    if (!animaCamOn) 
    {
        animaCam.enabled = false;
    }
    else 
    {
       animaCam.enabled = true;
    }

     if (!logoCamOn) 
    {
        logoCam.enabled = false;
    }
    else 
    {
       logoCam.enabled = true;
    }

    if(!showMenuOptions)
    {
        showMenuOptions = false;
    }
    else
    {
        showMenuOptions = true;
    }
 }


function OnGUI () 
{
  //set up scaling
    var rx : float = Screen.width / native_width;
    var ry : float = Screen.height / native_height;

    GUI.matrix = Matrix4x4.TRS (Vector3(0, 0, 0), Quaternion.identity, Vector3 (rx, ry, 1));

    //now create your GUI normally, as if you were in your native resolution
    //The GUI.matrix will scale everything automatically.


    if (!btnTexture) // This is the Route button that triggers the "showMenuOption"
    {
        Debug.LogError("Please assign a texture on the inspector");
        return;
    }
        // Make sure we only call GUI.Window if showMenuOption is true.
    if(GUI.Button(Rect(100, 200, 40, 25), btnTexture)) 

        showMenuOptions = !showMenuOptions;

        if(showMenuOptions)
        {
        // Make a background GUI box for showMenuOption
        GUI.Box (Rect (12,2,350,100),"Choose to play an animation:");
        GUI.DrawTexture(Rect(120,30,300,85), bgrImage);
    logoCamOn = !logoCamOn;                     // In this configuration showMenuOptions is on/off with logoCam activated as a preview.

        // Make the first button. If it is pressed, Animation (1) will be executed
        if (GUI.Button (Rect (10,14,100,20), "Anima1")) 
            {
            animaCamOn = !animaCamOn;   // animaCamOn disabled. In this configuration showMenuOptions is on/off with logoCam activated. On "Anima1" btn clicked, logoCamera stays on.Error!!!
            logoCamOn = !logoCamOn;
            animaCam.cullingMask = Animator1Mask;
            runAnima1 = !runAnima1;             
        }

    // Make the second button. If it is pressed, Animation (2) will be executed
           if (GUI.Button (Rect (10,36,100,20), "Anima2")) 
            {
            animaCamOn = !animaCamOn;
        logoCamOn = !logoCamOn;
            animaCam.cullingMask = Animator2Mask;
            runAnima2 = !runAnima2;
            }

    // Make the third button. If it is pressed, Animation (3) will be executed
        if (GUI.Button (Rect (10,56,100,20), "Anima3")) 
            {
            animaCamOn = !animaCamOn;
        logoCamOn = !logoCamOn;
            animaCam.cullingMask = Animator3Mask;
            runAnima3 = !runAnima3;             }

    // Make the forth button. If it is pressed, Animation (4) will be executed
        if (GUI.Button (Rect (10,88,100,20), "Anima4")) 
            {
            animaCamOn = !animaCamOn;
        logoCamOn = !logoCamOn;
            animaCam.cullingMask = Animator4Mask;
            runAnima4 = !runAnima4;
        }

        // Make the fifth button. If it is pressed, Animation (5) will be executed
        if (GUI.Button (Rect (10,110,100,20), "Anima5")) 
            {
            animaCamOn = !animaCamOn;
        logoCamOn = !logoCamOn;
            animaCam.cullingMask = Animator5Mask;
            runAnima5 = !runAnima5;
        }
    }
}