我创造了一个团结c#的游戏。玩家拥有“exp”,从游戏中的某些东西中获益。当“exp”足够时,玩家将获得一个等级,或者通常我们将其称为等级。
如果“exp”达到5级体验,我的游戏玩家可以一次获得5级。 因此,电路板将在1到5级内显示5次文本内容。 当玩家单击“确定”时,每个棋盘将交替显示,然后水平板将再次显示另一个级别的文本。
我使用了来自assetstore的GUIANIMFREE系统,该系统用于动画UI移入或移出效果。 到目前为止,我已经完成了升级显示板,但我的代码有一个错误。 代码如下:
void Start () {
Player = GameObject.FindGameObjectWithTag ("player").GetComponent<player> ();
leveldb = GameObject.Find ("levelDatabase").GetComponent<levelDatabase> ();
if (Player.level < 50) {
nextLevel = Player.level + 1;
}
run = 1;
}
void Awake() {
if(enabled)
{
// Set GUIAnimSystemFREE.Instance.m_AutoAnimation to false in Awake() will let you control all GUI Animator elements in the scene via scripts.
GUIAnimSystemFREE.Instance.m_AutoAnimation = false;
}
levelBoard.MoveOut (GUIAnimSystemFREE.eGUIMove.Self); **// This will Hide The Board Level First**
}
void FixedUpdate () {
if (run == 1) {
ex = leveldb.levels.FindIndex (j => j.levelx == nextLevel); // **This is use to check nextLevel in LevelDatabase if there is a number level inside the db**
if (ex >= 0) {
if (Player.exp >= leveldb.levels [ex].exp1) { // **If Player Exp if Equal Larger then nextLevel Exp in database**
run = 0;
LevelUp (); // **Leveling Up**
}
}
}
}
public void LevelUp() {
levelBoard.MoveIn (GUIAnimSystemFREE.eGUIMove.SelfAndChildren); // **Show The Board Level**
Player.level = Player.level + 1;
this.gameObject.transform.GetChild (2).GetComponent<TextMeshProUGUI> ().text = Player.level.ToString (); // **Add the text number Level to board Child**
Player.coin = Player.coin + leveldb.levels [ex].coin;
Player.gem = Player.gem + leveldb.levels [ex].gem;
this.gameObject.transform.GetChild (5).GetComponent<TextMeshProUGUI> ().text = "+" + leveldb.levels [ex].coin.ToString();
this.gameObject.transform.GetChild (6).GetComponent<TextMeshProUGUI> ().text = "+" + leveldb.levels [ex].gem.ToString();
}
public void OnClickOKLevelBoard() {
levelBoard.MoveOut (GUIAnimSystemFREE.eGUIMove.SelfAndChildren); //**Close the Board Level When OK is clicked**
if (Player.level < 50) {
nextLevel = Player.level + 1;
}
run = 1;
}
数据库级别是这样的: With Paramater:Level,Exp Start From,Exp End From,Coin,Gem,prize1,prize2,prize3)
levels.Add (new level (1, 5, 29, 0, 10, 0, 0, 0));
levels.Add (new level (2, 30, 179, 0, 30, 0, 0, 0));
levels.Add (new level (3, 180, 209, 0, 80, 0, 0, 0));
levels.Add (new level (4, 210, 349, 0, 100, 0, 0, 0));
levels.Add (new level (5, 350, 499, 0, 130, 0, 0, 0));
levels.Add (new level (6, 500, 639, 1, 150, 0, 0, 0));
levels.Add (new level (7, 640, 759, 1, 200, 0, 0, 0));
levels.Add (new level (8, 760, 879, 2, 240, 0, 0, 0));
levels.Add (new level (9, 880, 969, 2, 260, 0, 0, 0));
levels.Add (new level (10, 970, 1119, 2, 300, 0, 0, 0));
当我向玩家添加500 Exp时,从数据库级别如果玩家等级从0开始,那么这将达到等级6,因为我们可以在数据库级别看到6 Exp从500开始。
我们说我们向玩家添加500 Exp。代码中发生的事情是:
这是一个错误,因为它应该在6级之前显示6次。
将500 Exp添加到播放器时我想要的是:
注意:如果exp达到exp级别,我使用fixedupdate()来检查循环。
怎么做?我认为我的逻辑是正确的。但是当在编辑器中运行时,它不会像它一样。
由于
丹尼斯
答案 0 :(得分:0)
我改变了放置代码的方式。
void Start () {
Player = GameObject.FindGameObjectWithTag ("player").GetComponent<player> ();
leveldb = GameObject.Find ("levelDatabase").GetComponent<levelDatabase> ();
if (Player.level < 50) {
nextLevel = Player.level + 1;
}
StartCoroutine (startcheck ());
}
IEnumerator startcheck() {
yield return new WaitForSeconds (1);
if (go == true) {
Debug.Log ("DOING SOMETHING : " + i);
i++;
ex = leveldb.levels.FindIndex (j => j.levelx == nextLevel);
if (ex >= 0) {
if (Player.exp >= leveldb.levels [ex].exp1) {
go = false;
LevelUp ();
Debug.Log ("MASUK : " + Player.exp + " : " + leveldb.levels [ex].exp1);
} else {
Start ();
}
} else {
Start ();
}
} else {
Debug.Log ("NOT DOING ANTYHTING");
}
}
public void LevelUp() {
levelBoard.ResetAllChildren ();
levelBoard.MoveIn (GUIAnimSystemFREE.eGUIMove.SelfAndChildren);
Player.level = Player.level + 1;
this.gameObject.transform.GetChild (2).GetComponent<TextMeshProUGUI> ().text = Player.level.ToString ();
Player.coin = Player.coin + leveldb.levels [ex].coin;
Player.gem = Player.gem + leveldb.levels [ex].gem;
this.gameObject.transform.GetChild (5).GetComponent<TextMeshProUGUI> ().text = "+" + leveldb.levels [ex].coin.ToString();
this.gameObject.transform.GetChild (6).GetComponent<TextMeshProUGUI> ().text = "+" + leveldb.levels [ex].gem.ToString();
}
public void OnClickOKLevelBoard() {
levelBoard.MoveOut (GUIAnimSystemFREE.eGUIMove.Self);
go = true;
if (Player.level < 50) {
nextLevel = Player.level + 1;
} else {
go = false;
}
Start ();
}
与此类似,水平板的出现次数达到exp级别。