public void gameTimer() { MGGlobalDataCenter.defaultCenter().totalGameTime -= 0.01f; int frontNum = (int)Math.Floor(MGGlobalDataCenter.defaultCenter().totalGameTime); int laterNum = (int)((MGGlobalDataCenter.defaultCenter().totalGameTime - frontNum) * 100); if (MGGlobalDataCenter.defaultCenter().totalGameTime <= 0f) { CancelInvoke("gameTimer"); //游戏结束 if (GameObject.Find("role").GetComponent <RoleAnimController>().isDead || GameObject.Find("role1").GetComponent <RoleAnimController>().isDead) { return; } MGGlobalDataCenter.defaultCenter().overSenceUIName = "victoryFrontGameUI"; Application.LoadLevel("overSence"); MGMsgModel gameoverModel = new MGMsgModel(); gameoverModel.eventId = RoleActEventEnum.gameoverEventId; gameoverModel.gameobjectName = MGGlobalDataCenter.defaultCenter().overSenceUIName; mgNetWorking.sendMessageToPeer(JsonMapper.ToJson(gameoverModel)); return; } if (laterNum < 10) { gameTimerLabel.GetComponent <UILabel>().text = frontNum + ":0" + laterNum; } else { gameTimerLabel.GetComponent <UILabel>().text = frontNum + ":" + laterNum; } }
public void jump(MGNotification notification) { MGNotificationCenter.defaultCenter().postNotification(buttonEventId(RoleButtonEvent.upFormerEventId), notification); //if (roleAnimaController.isRoll || roleAnimaController.isPressDown) return; if (transform.localScale.y < 0 || roleAnimaController.isRoll) { Debug.Log("jump"); if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.jumpFormerEventId)); } return; } if (roleAnimaController.isFirstJump && !roleAnimaController.isSecondJump && jumpCount == 0) { Debug.Log("一段跳"); isGround = false; Vector3 velocity = rigidbody2D.velocity; velocity.y = jumpVelocity; rigidbody2D.velocity = velocity; jumpCount = 1; //如果没有发送给对方,则发送消息 if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.jumpFormerEventId)); } } //如果不在地面上,且一段跳了,则二段跳 else if (roleAnimaController.isFirstJump && roleAnimaController.isSecondJump && jumpCount == 1) { Debug.Log("二段跳"); Vector3 velocity = rigidbody2D.velocity; if (velocity.y < -1.0f) { velocity.y = jumpSecond + 3; } else { velocity.y = jumpSecond; } rigidbody2D.velocity = velocity; jumpCount = 2; if (notification.objc == null) { mgNetWorking.sendMessageToPeer(objcToJson(RoleActEventEnum.jumpFormerEventId)); } } }