在Unity play和android设备上,具有5层的摄像头脚本具有奇怪的行为

在Unity play和android设备上,具有5层的摄像头脚本具有奇怪的行为,android,debugging,user-interface,camera,unity3d,Android,Debugging,User Interface,Camera,Unity3d,我需要一些帮助来解决相机脚本和GUI.button菜单的问题 以下是我的场景层次: 有一个摄像头(名为“animaCam”),可以看到5层。在每一层上,都有一个纹理动画脚本连接到游戏对象(立方体),如果在gui.box(菜单)上单击合适的gui.button,该脚本将播放动画 在此摄像头之前,还有另一个摄像头(名为“logoCam”),用作徽标屏幕,只能看到一层 通过此配置,我希望实现以下功能。当用户单击gui.button时,会弹出一个gui.box,最初显示logoCam和五个gui.but

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

以下是我的场景层次:

有一个摄像头(名为“animaCam”),可以看到5层。在每一层上,都有一个纹理动画脚本连接到游戏对象(立方体),如果在gui.box(菜单)上单击合适的gui.button,该脚本将播放动画

在此摄像头之前,还有另一个摄像头(名为“logoCam”),用作徽标屏幕,只能看到一层

通过此配置,我希望实现以下功能。当用户单击gui.button时,会弹出一个gui.box,最初显示logoCam和五个gui.button可供选择

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

a。应该隐藏logoCam B应该启用animaCam C应选择合适的层和合适的立方体 D应该在立方体上启动动画脚本

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

a。一旦用户单击“showMenuOptions”的gui.button,android设备上的菜单将保持打开状态。即使再次单击按钮以关闭,它仍保持在屏幕上。在Unity player上,菜单的gui.button按应有的方式运行,单击打开/关闭

b。在用户选择播放(例如第一个动画)时,执行函数并播放动画。当用户单击启用/禁用“showMenuOption”的另一个gui.button时,菜单关闭,但动画继续播放。它应该在菜单关闭时关闭

我相信,错误一定在更新函数中。我尝试了我能想到的一切,但没有多大成功

请看下面的代码。如果我弄错了什么,请发表一些想法或更好的代码片段。 我真的需要让摄像头和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;
        }
    }
}