public void guaiwu(int x, int y, TileData otherTileData) { Guaiwu guaiwu = otherTileData.gameObject.GetComponent <Guaiwu>(); _DM.infoDabuguo = "你打不过它。\r\n"; _DM.infoDabuguo += "怪物属性:\n"; _DM.infoDabuguo += "生命:" + guaiwu.shengming + "\n"; _DM.infoDabuguo += "攻击:" + guaiwu.gongji + "\n"; _DM.infoDabuguo += "防御:" + guaiwu.fangyu + "\n"; _DM.infoDabuguo += "金币:" + guaiwu.jinbi + "\n"; _DM.infoDabuguo += "经验:" + guaiwu.jingyan + "\n"; if (_PA._gongji <= guaiwu.fangyu) { _DM.state = "dabuguo"; } else { int shanghai = _PA._gongji - guaiwu.fangyu; float cishu = Mathf.Ceil(guaiwu.shengming / shanghai); float zongshanghai = 0; if (guaiwu.gongji > _PA._fangyu) { float shoushang = guaiwu.gongji - _PA._fangyu; zongshanghai = shoushang * cishu; } if (zongshanghai >= _PA._shengming) { _DM.state = "dabuguo"; } else { _PA._shengming -= (int)zongshanghai; _PA._jingyan += guaiwu.jingyan; _PA._jinbi += guaiwu.jinbi; _DM.tipContent = "经验+" + guaiwu.jingyan + ",金币+" + guaiwu.jinbi; _DM.tipTime = 3f; GameObject.Destroy(guaiwu.gameObject); if (otherTileData.GetUserFlag(9)) { SceneManager.LoadScene(1); } otherTileData.Clear(); } } }
void OnGUI() { GUI.skin.box.normal.textColor = new Vector4(1, 1, 1, 1); GUI.skin.box.padding = new RectOffset(15, 15, 15, 15); GUI.skin.box.fontSize = scaleGUI(8); GUI.skin.box.alignment = TextAnchor.UpperLeft; GUI.skin.box.normal.background = dialogboxbg; GUI.skin.button.fontSize = scaleGUI(8); switch (state) { case "dialog": { player.canMove = false; if (!string.IsNullOrEmpty(_text)) { dialogbox = new Rect( Screen.width / 2 - scaleGUI(95), Screen.height / 2 - scaleGUI(113), scaleGUI(190), scaleGUI(190)); GUI.Box(dialogbox, _text); } if (_choices == null) { if (GUI.Button(new Rect( Screen.width / 2 - scaleGUI(95), Screen.height / 2 + scaleGUI(50), scaleGUI(190), scaleGUI(30)), "继续")) { Dialoguer.ContinueDialogue(); } } else { pressed = false; for (int i = _choices.Length - 1; i >= 0; i--) { if (GUI.Button(new Rect( Screen.width / 2 - scaleGUI(95), Screen.height / 2 + scaleGUI((i - _choices.Length + 2) * 35), scaleGUI(190), scaleGUI(30)), _choices[i])) { Dialoguer.ContinueDialogue(i); } } } } break; case "dabuguo": { player.canMove = false; GUI.Box(new Rect( Screen.width / 2 - scaleGUI(72), Screen.height / 2 - scaleGUI(120), scaleGUI(144), scaleGUI(220)), infoDabuguo); if (GUI.Button(new Rect( Screen.width / 2 - scaleGUI(60), Screen.height / 2 + scaleGUI(45), scaleGUI(120), scaleGUI(35)), "知道了")) { state = string.Empty; player.canMove = true; } } break; case "floorchange": { if (dialogTime > 0) { dialogTime -= Time.deltaTime; GUI.Box(new Rect( Screen.width / 2 - scaleGUI(72), Screen.height / 2 - scaleGUI(20), scaleGUI(144), scaleGUI(40)), "当前第 " + _GM.CurrentFloor + " 层"); } else { dialogTime = 0; state = string.Empty; } } break; case "tujian": if (Input.GetMouseButton(0)) { GameObject mycamera = GameObject.Find("Camera"); Vector3 position = mycamera.GetComponent <Camera>().ScreenToWorldPoint(Input.mousePosition); TileIndex ti = _TM._TileSystem.ClosestTileIndexFromWorld(position); TileData tile = _TM._TileSystem.GetTile(ti); if (tile != null && tile.GetUserFlag(3)) { Guaiwu guaiwu = tile.gameObject.GetComponent <Guaiwu>(); string info = ""; if (!tile.GetUserFlag(10)) { if (_PA._gongji <= guaiwu.fangyu) { info = "你破不了它的防御。\n"; } else { int shanghai = _PA._gongji - guaiwu.fangyu; float cishu = Mathf.Ceil(guaiwu.shengming / shanghai); float zongshanghai = 0; if (guaiwu.gongji > _PA._fangyu) { float shoushang = guaiwu.gongji - _PA._fangyu; zongshanghai = shoushang * cishu; } info = "战胜它你将损失:" + zongshanghai + "生命。\n"; } } info += "生命:" + guaiwu.shengming + " / "; info += "攻击:" + guaiwu.gongji + " / "; info += "防御:" + guaiwu.fangyu + "\n"; info += "金币:" + guaiwu.jinbi + " / "; info += "经验:" + guaiwu.jingyan; if (position.y > -5) { //显示在下面 GUI.Box(new Rect( Screen.width / 2 - scaleGUI(95), Screen.height / 2 + scaleGUI(30), scaleGUI(190), scaleGUI(50)), info); } else { //显示在上面 GUI.Box(new Rect( Screen.width / 2 - scaleGUI(95), Screen.height / 2 - scaleGUI(113), scaleGUI(190), scaleGUI(50)), info); } } } break; case "feixing": player.canMove = false; for (int i = 1; i < _GM.maxFloor + 1; i++) { int y = i % 3; if (y == 0) { y = -1; } else if (y == 2) { y = 0; } int z = (i - 1) / 3; if (GUI.Button( new Rect(Screen.width / 2 - scaleGUI(60 * y + 35), Screen.height / 2 - scaleGUI(113) + scaleGUI(25 * z), scaleGUI(50), scaleGUI(20)), "第 " + i + " 层")) { _GM.changeFloor(i); state = ""; player.canMove = true; } } break; } if (tipTime > 0 && !string.IsNullOrEmpty(tipContent)) { GUI.skin.box.alignment = TextAnchor.MiddleCenter; GUI.Box(new Rect( Screen.width / 2 - scaleGUI(95), Screen.height / 2 + scaleGUI(50), scaleGUI(190), scaleGUI(30)), tipContent); tipTime -= Time.deltaTime; } else { tipTime = 0; tipContent = string.Empty; } if (string.IsNullOrEmpty(state)) { player.canMove = true; } }