Unity游戏关卡的顺序开启代码

//另外建的Round关卡属性类及构造函数

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Round  {
    
    public string name;
    public int ID;
    public string Activation{ get; set;}
    public   Round(string name,int id,string act){
        this.name = name;
        this.ID = id;
        this.Activation = act;
    }
}

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Round  {
    
    public string name;
    public int ID;
    public string Activation{ get; set;}
    public   Round(string name,int id,string act){
        this.name = name;
        this.ID = id;
        this.Activation = act;
    }
}


//正文代码


using System.Collections;

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;

public class xinxin : MonoBehaviour {

    Dictionary<int,Round> roundActivation=new Dictionary<int, Round>();
    GameObject game;
    // Use this for initialization
    void Start () {
        //添加8个关卡
        Round round1 = new Round ("Round",1,"激活");
        Round round2 = new Round ("Round (1)",2,"失活");
        Round round3 = new Round ("Round (2)",3,"失活");
        Round round4 = new Round ("Round (3)",4,"失活");
        Round round5 = new Round ("Round (4)",5,"失活");
        Round round6 = new Round ("Round (5)",6,"失活");
        Round round7 = new Round ("Round (6)",7,"失活");
        Round round8 = new Round ("Round (7)",8,"失活");


        roundActivation.Add (round1.ID,round1);
        roundActivation.Add (round2.ID,round2);
        roundActivation.Add (round3.ID,round3);
        roundActivation.Add (round4.ID,round4);
        roundActivation.Add (round5.ID,round5);
        roundActivation.Add (round6.ID,round6);
        roundActivation.Add (round7.ID,round7);
        roundActivation.Add (round8.ID,round8);


    }


    public void button(){

        for(int i=1;i<roundActivation.Count+1;i++){


             game = GameObject.Find (roundActivation[i].name);

            if (roundActivation [i].Activation == "失活" ) {

                game.transform.GetChild (2).gameObject.GetComponent<Image> ().enabled = false;
                game.transform.GetChild (1).gameObject.GetComponent<Image> ().enabled = true;

                roundActivation [i].Activation = "激活";

                break;
            } else {
                if(game.transform.GetChild (5).gameObject.GetComponent<Image> ().sprite != null){
                    continue;
                }
                for(int j=3;j<6;j++){
                    if (game.transform.GetChild (j).gameObject.GetComponent<Image> ().sprite == null) {
                        game.transform.GetChild (j).gameObject.GetComponent<Image> ().sprite = Resources.Load<Sprite> ("Level_Star_2");
                        game.transform.GetChild (j).gameObject.GetComponent<Image> ().color = Color.white;
                        break;
                    }
                }
                break;
            }
        }
    }




  • 2
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值