概述
//另外建的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;
}
}
}
最后
以上就是缓慢河马为你收集整理的Unity游戏关卡的顺序开启代码的全部内容,希望文章能够帮你解决Unity游戏关卡的顺序开启代码所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复