{"id":215,"date":"2017-09-17T03:36:55","date_gmt":"2017-09-16T18:36:55","guid":{"rendered":"http:\/\/uniblo.biz\/?p=215"},"modified":"2017-09-28T23:34:12","modified_gmt":"2017-09-28T14:34:12","slug":"chapter6_toonline","status":"publish","type":"post","link":"https:\/\/uniblo.biz\/unity\/mmogame\/chapter6_toonline","title":{"rendered":"Unity\u30aa\u30f3\u30e9\u30a4\u30f3\u30b2\u30fc\u30e0\u4f5c\u6210\u3010Chapter6\u3011\u30aa\u30f3\u30e9\u30a4\u30f3\u30b2\u30fc\u30e0\u5316"},"content":{"rendered":"
\u9042\u306b\u30aa\u30f3\u30e9\u30a4\u30f3\u30b2\u30fc\u30e0\u5316\u307e\u3067\u6765\u307e\u3057\u305f\uff01<\/p>\n
\u304c\u3001\u307e\u305a\u306f\u4eca\u304b\u3089\u4f5c\u308b\u7269\u3092\u30a4\u30e1\u30fc\u30b8\u3057\u3066\u307f\u307e\u3057\u3087\u3046\u3002<\/p>\n
\u30b2\u30fc\u30e0\u7684\u306b\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306a\u3082\u306e\u3092\u4f5c\u308a\u307e\u3059\u3002<\/p>\n
<\/a><\/p>\n Chapter5\u307e\u3067\u306f\u30aa\u30d5\u30e9\u30a4\u30f3\u3067\u52d5\u304f\u30b2\u30fc\u30e0\u3067\u3057\u305f\u304c\u3001\u4eca\u56de\u304b\u3089\u30aa\u30f3\u30e9\u30a4\u30f3\u3067\u52d5\u304f\u3088\u3046\u306b\u8a2d\u5b9a\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n \u30aa\u30f3\u30e9\u30a4\u30f3\u3067\u52d5\u304f\u3088\u3046\u306b\u8a2d\u5b9a\u3059\u308b\u305f\u3081\u306b\u306f\u4ee5\u4e0b\u306e2\u70b9\u3092\u8a2d\u5b9a\u3059\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n \u4eca\u56de\u306e\u30b2\u30fc\u30e0\u3067\u306f\u30d7\u30ec\u30a4\u30e4\u30fc\u304c\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u3068\u540c\u6642\u306b\u30d7\u30ec\u30a4\u30e4\u30fc\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u751f\u6210\u3057\u52d5\u3051\u308b\u3088\u3046\u306b\u3057\u306a\u3051\u308c\u3070\u306a\u308a\u307e\u305b\u3093\u3002<\/p>\n \u306a\u306e\u3067\u3001\u30d7\u30ec\u30a4\u30e4\u30fc\u63a5\u7d9a\u6642\u306b\u64cd\u4f5c\u3059\u308b\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u751f\u6210\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n \u4eee\u306b\u3053\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u540d\u524d\u3092\u30b2\u30fc\u30e0\u3092\u7ba1\u7406\u3059\u308b\u306e\u3067GameManager<\/strong>\u3068\u540d\u3065\u3051\u307e\u3059\u3002<\/p>\n GameManager\u306b\u4ee5\u4e0b\u306eGameManagerScript\u3092\u30a2\u30bf\u30c3\u30c1\u3057\u307e\u3059\u3002<\/p>\n GameManagerScript\u306fScene battle\u304c\u8aad\u307f\u8fbc\u307e\u308c\u305f\u76f4\u5f8c\u306b\u51e6\u7406\u304c\u958b\u59cb\u3055\u308c\u307e\u3059\u3002<\/p>\n \u3064\u307e\u308a\u3001Scene battle\u304c\u8aad\u307f\u8fbc\u307e\u308c\u305f\u76f4\u5f8c\u306b\u81ea\u30d7\u30ec\u30a4\u30e4\u30fc\u3092\u4f5c\u6210\u3057\u307e\u3059\u3002<\/p>\n Player\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30aa\u30f3\u30e9\u30a4\u30f3\u5316\u8a2d\u5b9a\u306f\u4ee5\u4e0b\u306e\u624b\u9806\u3092\u884c\u3044\u307e\u3059\u3002<\/p>\n\n
\u00a0\u30b2\u30fc\u30e0\u3092\u7ba1\u7406\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n
GameManager.cs\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n
using System;\r\nusing System.Collections;\r\nusing UnityEngine;\r\nusing UnityEngine.SceneManagement;\r\n\r\npublic class GameManagerScript : Photon.PunBehaviour\r\n{\r\n \/\/\u8ab0\u304b\u304c\u30ed\u30b0\u30a4\u30f3\u3059\u308b\u5ea6\u306b\u751f\u6210\u3059\u308b\u30d7\u30ec\u30a4\u30e4\u30fcPrefab\r\n public GameObject playerPrefab; \r\n\r\n void Start()\r\n {\r\n if (!PhotonNetwork.connected) \/\/Phootn\u306b\u63a5\u7d9a\u3055\u308c\u3066\u3044\u306a\u3051\u308c\u3070\r\n {\r\n SceneManager.LoadScene(\"Launcher\"); \/\/\u30ed\u30b0\u30a4\u30f3\u753b\u9762\u306b\u623b\u308b\r\n return; \r\n }\r\n \/\/Photon\u306b\u63a5\u7d9a\u3057\u3066\u3044\u308c\u3070\u81ea\u30d7\u30ec\u30a4\u30e4\u30fc\u3092\u751f\u6210\r\n GameObject Player = PhotonNetwork.Instantiate(this.playerPrefab.name, new Vector3(0f, 0f, 0f), Quaternion.identity, 0);\r\n }\r\n\r\n \/\/ Update is called once per frame\r\n void Update () {\r\n\t\t\r\n\t}\r\n}\r\n<\/pre>\n
Player\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u8a2d\u5b9a\u3068\u30d7\u30ec\u30cf\u30d6\u5316<\/h2>\n
\n
\u5909\u66f4\u5f8c\u306eCharacterControlScript.cs\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n
using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\n\r\npublic class CharacterControlScript : MonoBehaviour {\r\n\r\n \/\/\u30aa\u30f3\u30e9\u30a4\u30f3\u5316\u306b\u5fc5\u8981\u306a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8a2d\u5b9a\r\n public PhotonView myPV;\r\n public PhotonTransformView myPTV;\r\n\r\n private Camera mainCam;\r\n\r\n \/\/\u79fb\u52d5\u51e6\u7406\u306b\u5fc5\u8981\u306a\u30b3\u30f3\u30dd\u30fc\u30cd\u30f3\u30c8\u3092\u8a2d\u5b9a\r\n public Animator animator; \/\/\u30e2\u30fc\u30b7\u30e7\u30f3\u3092\u30b3\u30f3\u30c8\u30ed\u30fc\u30eb\u3059\u308b\u305f\u3081Animator\u3092\u53d6\u5f97\r\n public CharacterController controller; \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u79fb\u52d5\u3092\u7ba1\u7406\u3059\u308b\u305f\u3081CharacterController\u3092\u53d6\u5f97\r\n\r\n \/\/\u79fb\u52d5\u901f\u5ea6\u7b49\u306e\u30d1\u30e9\u30e1\u30fc\u30bf\u7528\u5909\u6570(inspector\u30d3\u30e5\u30fc\u3067\u8a2d\u5b9a)\r\n public float speed; \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u79fb\u52d5\u901f\u5ea6\r\n public float jumpSpeed; \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u30b8\u30e3\u30f3\u30d7\u529b\r\n public float rotateSpeed; \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u65b9\u5411\u8ee2\u63db\u901f\u5ea6\r\n public float gravity; \/\/\u30ad\u30e3\u30e9\u306b\u304b\u304b\u308b\u91cd\u529b\u306e\u5927\u304d\u3055\r\n\r\n Vector3 targetDirection; \/\/\u79fb\u52d5\u3059\u308b\u65b9\u5411\u306e\u30d9\u30af\u30c8\u30eb\r\n Vector3 moveDirection = Vector3.zero;\r\n\r\n \/\/ Start\u95a2\u6570\u306f\u5909\u6570\u3092\u521d\u671f\u5316\u3059\u308b\u305f\u3081\u306e\u95a2\u6570\r\n void Start () {\r\n if (myPV.isMine) \/\/\u81ea\u30ad\u30e3\u30e9\u3067\u3042\u308c\u3070\u5b9f\u884c\r\n {\r\n \/\/MainCamera\u306etarget\u306b\u3053\u306e\u30b2\u30fc\u30e0\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u8a2d\u5b9a\r\n mainCam = Camera.main; \r\n mainCam.GetComponent<CameraScript>().target = this.gameObject.transform;\r\n }\r\n }\r\n\r\n \/\/ Update\u95a2\u6570\u306f1\u30d5\u30ec\u30fc\u30e0\u306b\uff11\u56de\u5b9f\u884c\u3055\u308c\u308b\r\n void Update () {\r\n\r\n if (!myPV.isMine)\r\n {\r\n return;\r\n }\r\n\r\n moveControl(); \/\/\u79fb\u52d5\u7528\u95a2\u6570\r\n RotationControl(); \/\/\u65cb\u56de\u7528\u95a2\u6570\r\n\r\n \/\/\u6700\u7d42\u7684\u306a\u79fb\u52d5\u51e6\u7406\r\n \/\/(\u3053\u308c\u304c\u7121\u3044\u3068CharacterController\u306b\u60c5\u5831\u304c\u9001\u3089\u308c\u306a\u3044\u305f\u3081\u3001\u52d5\u3051\u306a\u3044)\r\n controller.Move(moveDirection * Time.deltaTime);\r\n\r\n \/\/\u30b9\u30e0\u30fc\u30ba\u306a\u540c\u671f\u306e\u305f\u3081\u306bPhotonTransformView\u306b\u901f\u5ea6\u5024\u3092\u6e21\u3059\r\n Vector3 velocity = controller.velocity;\r\n myPTV.SetSynchronizedValues(velocity, 0); \r\n }<\/pre>\n