Unity3d 如何在解锁时禁用LockTexture?

Unity3d 如何在解锁时禁用LockTexture?,unity3d,unityscript,Unity3d,Unityscript,我正在构建一个包含8个关卡的游戏。我使用以下脚本切换下一个级别。但当我解锁一个关卡时,锁定纹理仍保留在窗口中。我想在解锁新关卡时移除锁定纹理。请帮帮我 我的代码如下: LevelIndex = 0; for ( GridIndexB = 0 ; GridIndexB < LevelsGrid.y ; GridIndexB++ ) { for ( GridIndexA = 0 ; GridIndexA < LevelsGrid.x ; GridIndexA++ ) {

我正在构建一个包含8个关卡的游戏。我使用以下脚本切换下一个级别。但当我解锁一个关卡时,锁定纹理仍保留在窗口中。我想在解锁新关卡时移除锁定纹理。请帮帮我

我的代码如下:

LevelIndex = 0;

for ( GridIndexB = 0 ; GridIndexB < LevelsGrid.y ; GridIndexB++ )
{
    for ( GridIndexA = 0 ; GridIndexA < LevelsGrid.x ; GridIndexA++ )
    {
        LevelIndex++;

        GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10) ,LevelTexture.width, LevelTexture.height), LevelTexture);//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture

        if ( TotalPoints >= PointsToUnlock[LevelIndex - 1] )
        {
            if ( GUI.Button(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LevelIndex.ToString()) )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
            {
                PlayerPrefs.SetInt("currentLevel", LevelIndex); 
                Application.LoadLevel("level" + LevelIndex);    
            }
        }
        else
        {
            GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LockTexture);

        }
    }
}
LevelIndex=0;
对于(GridIndexB=0;GridIndexB=PointsToUnlock[LevelIndex-1])
{
如果(GUI.Button(Rect((Screen.width-LevelsGrid.x*(LevelTexture.width+10))*0.5+GridIndexA*(LevelTexture.width+10)、60+GridIndexB*(LevelTexture.height+10)、LevelTexture.width、LevelTexture.height、LevelIndex.ToString())//Laps.ToString()+“+GameController.GetComponent(“GameController”).lapstoString()));//绘制HUD纹理
{
PlayerPrefs.SetInt(“当前级别”,级别索引);
应用程序。加载级别(“级别”+级别索引);
}
}
其他的
{
GUI.DrawTexture(Rect((Screen.width-LevelsGrid.x*(LevelTexture.width+10))*0.5+GridIndexA*(LevelTexture.width+10)、60+GridIndexB*(LevelTexture.height+10)、LevelTexture.width、LevelTexture.height)、LockTexture);
}
}
}
完整脚本如下所示:

var TitleText:String = "SINGLE PLAYER";
var NumberOfPlayers:int = 1;

var Levels:int = 8;
private var LevelIndex:int = 0;

var PointsToUnlock:Array = new Array(0, 2, 6, 12, 24, 36, 48, 56);

var LevelsGrid:Vector2 = Vector2(4,2);
private var GridIndexA:int = 0;
private var GridIndexB:int = 0;

var LevelTexture:Texture2D;
var LockTexture:Texture2D;

//~ var HowToPlayTexture:Texture2D;
var BGPattern:Texture2D;

//This script displays the HUD, with current weapon, ammo left, Health, Shield, and score
var GUIskin:GUISkin; //The skin gui we'll use

private var LevelPoints:Array = new Array();
private var TotalPoints:int = 0;

function Start()
{
    if ( camera.main.GetComponent("StartMenu") )
        camera.main.GetComponent("StartMenu").MenuLevel = transform;
    else if ( camera.main.GetComponent("EndMenu") )
        camera.main.GetComponent("EndMenu").MenuLevel = transform;

    LevelPoints.Clear();

    for ( LevelIndex = 1 ; LevelIndex <= transform.GetComponent("LevelsMenu").Levels ; LevelIndex++ )
    {
        LevelPoints.Push(PlayerPrefs.GetInt(("level" + LevelIndex + "Points").ToString()));

        TotalPoints += LevelPoints[LevelIndex - 1];
    }

    print(LevelPoints);
    print(TotalPoints);
}

function OnGUI()
{
    GUI.skin = GUIskin; //The skin gui we'll use
    GUI.depth = 0;

    GUI.DrawTexture(Rect( 0, 0 ,Screen.width, Screen.height), BGPattern);//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture

    GUI.Label(Rect(0, 10, Screen.width, 70), TitleText);

    LevelIndex = 0;

    for ( GridIndexB = 0 ; GridIndexB < LevelsGrid.y ; GridIndexB++ )
    {
        for ( GridIndexA = 0 ; GridIndexA < LevelsGrid.x ; GridIndexA++ )
        {
            LevelIndex++;

            GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10) ,LevelTexture.width, LevelTexture.height), LevelTexture);//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture

            if ( TotalPoints >= PointsToUnlock[LevelIndex - 1] )
            {
                if ( GUI.Button(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LevelIndex.ToString()) )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
                {
                    PlayerPrefs.SetInt("currentLevel", LevelIndex); 
                    Application.LoadLevel("level" + LevelIndex);
                }
            }
            else
            {
                GUI.DrawTexture(Rect( (Screen.width - LevelsGrid.x * (LevelTexture.width + 10)) * 0.5 + GridIndexA * (LevelTexture.width + 10), 60 + GridIndexB * (LevelTexture.height + 10), LevelTexture.width, LevelTexture.height), LockTexture);
            }
        }
    }

    if ( GUI.Button(Rect( 10, Screen.height - 70, 140, 60), "BACK") )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
    {
        if ( camera.main.GetComponent("StartMenu") )
            camera.main.GetComponent("StartMenu").MenuLevel = camera.main.transform;
        else if ( camera.main.GetComponent("EndMenu") )
            camera.main.GetComponent("EndMenu").MenuLevel = camera.main.transform;

        Destroy(gameObject);
    }

    if ( GUI.Button(Rect( Screen.width - 410 , Screen.height - 70, 400, 60), "RESET LEVELS") )//Laps.ToString() + "/" + GameController.GetComponent("GameController").LapsToWin.ToString()); //Draw the HUD texture
    {
         LevelPoints.Clear();

         for ( LevelIndex = 1 ; LevelIndex <= transform.GetComponent("LevelsMenu").Levels ; LevelIndex++ )
         {
             PlayerPrefs.SetInt(("level" + LevelIndex + "Points").ToString(), 0);
         }

         TotalPoints = 0;
    }
}
var TitleText:String=“单人”;
变量NumberOfPlayers:int=1;
风险值水平:int=8;
私有var LevelIndex:int=0;
var PointsToUnlock:Array=新数组(0,2,6,12,24,36,48,56);
var-LevelsGrid:Vector2=Vector2(4,2);
私有变量GridIndexA:int=0;
私有变量GridIndexB:int=0;
var-LevelTexture:Texture2D;
纹理:纹理2d;
//~var HowToPlayTexture:Texture2D;
模式:纹理2d;
//此脚本显示HUD,包括当前武器、剩余弹药、生命值、盾牌和分数
var-GUIskin:GUIskin//我们将使用的皮肤gui
私有变量LevelPoints:Array=newarray();
私有var TotalPoints:int=0;
函数Start()
{
if(camera.main.GetComponent(“StartMenu”))
camera.main.GetComponent(“StartMenu”).MenuLevel=transform;
else if(camera.main.GetComponent(“EndMenu”))
camera.main.GetComponent(“EndMenu”).MenuLevel=transform;
LevelPoints.Clear();

对于(LevelIndex=1;LevelIndex供将来参考,请,请不要发布三次。这可能会导致尝试解决问题的努力支离破碎,并不必要地填满问题队列。