{"id":159,"date":"2017-09-14T07:04:20","date_gmt":"2017-09-13T22:04:20","guid":{"rendered":"http:\/\/uniblo.biz\/?p=159"},"modified":"2017-09-28T23:32:48","modified_gmt":"2017-09-28T14:32:48","slug":"chapter5_camera","status":"publish","type":"post","link":"http:\/\/uniblo.biz\/unity\/mmogame\/chapter5_camera","title":{"rendered":"Unity\u30aa\u30f3\u30e9\u30a4\u30f3\u30b2\u30fc\u30e0\u4f5c\u6210\u3010Chapter5\u3011\u30d7\u30ec\u30a4\u30e4\u30fc\u30ab\u30e1\u30e9\u306e\u8a2d\u5b9a"},"content":{"rendered":"

\u30ab\u30e1\u30e9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/h2>\n

\u30ab\u30e1\u30e9\u306f\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u76ee\u3068\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8<\/strong>\u3067\u3059\u3002<\/p>\n

\u57fa\u672c\u7684\u306b\u30b2\u30fc\u30e0\u306f\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u8996\u70b9\u306b\u306a\u308b\u4e00\u4eba\u79f0\u8996\u70b9\u304b\u3001\u5c11\u3057\u96e2\u308c\u305f\u3068\u3053\u308d\u304b\u3089\u81ea\u5206\u306e\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u6620\u3059\u4e09\u4eba\u79f0\u8996\u70b9\u306e\u3069\u3061\u3089\u304b\u3067\u3059\u3002<\/p>\n

\u4eca\u56de\u306f\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u5468\u308a\u304c\u3088\u304f\u898b\u3048\u308b\u4e09\u4eba\u79f0\u8996\u70b9\u306e\u30b2\u30fc\u30e0\u3092\u4f5c\u3063\u3066\u3044\u304d\u305f\u3044\u3068\u601d\u3044\u307e\u3059\u3002<\/p>\n

\u30ab\u30e1\u30e9\u306e\u8a2d\u5b9a<\/h2>\n

\u73fe\u5728\u306eHierarchy\u30d3\u30e5\u30fc\u306b\u306fMain Camera\u3068\u3044\u3046\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u304c\u3042\u308b\u306e\u3067\u305d\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3092\u6d41\u7528\u3057\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

\u4eca\u56de\u4f5c\u6210\u3059\u308b\u30ab\u30e1\u30e9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306einspector\u30d3\u30e5\u30fc\u306f\u4ee5\u4e0b\u306e\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\"\"<\/a><\/p>\n

\u4eca\u56de\u4f5c\u6210\u3059\u308b\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u30ab\u30e1\u30e9\u306e\u4f4d\u7f6e\u3068\u5411\u304d\u3092\u5236\u5fa1\u3059\u308bCameraScript\u306e\u307f\u3067\u3059\u3002<\/p>\n

\u4ee5\u4e0b\u3092\u53c2\u8003\u306bCameraScript\u3092\u4f5c\u6210\u3057\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n

CameraScript.cs\u306e\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\n
using System.Collections;\r\nusing System.Collections.Generic;\r\nusing UnityEngine;\r\nusing UnityEngine.UI;\r\n\r\npublic class CameraScript : MonoBehaviour\r\n{\r\n    private const float YAngle_MIN = -89.0f;   \/\/\u30ab\u30e1\u30e9\u306eY\u65b9\u5411\u306e\u6700\u5c0f\u89d2\u5ea6\r\n    private const float YAngle_MAX = 89.0f;     \/\/\u30ab\u30e1\u30e9\u306eY\u65b9\u5411\u306e\u6700\u5927\u89d2\u5ea6\r\n\r\n    public Transform target;    \/\/\u8ffd\u8de1\u3059\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306etransform\r\n    public Vector3 offset;      \/\/\u8ffd\u8de1\u5bfe\u8c61\u306e\u4e2d\u5fc3\u4f4d\u7f6e\u8abf\u6574\u7528\u30aa\u30d5\u30bb\u30c3\u30c8\r\n    private Vector3 lookAt;     \/\/target\u3068offset\u306b\u3088\u308b\u6ce8\u8996\u3059\u308b\u5ea7\u6a19\r\n\r\n    private float distance  = 10.0f;    \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3068\u30ab\u30e1\u30e9\u9593\u306e\u89d2\u5ea6\r\n    private float distance_min = 1.0f;  \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3068\u306e\u6700\u5c0f\u8ddd\u96e2\r\n    private float distance_max = 20.0f; \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3068\u306e\u6700\u5927\u8ddd\u96e2\r\n    private float currentX = 0.0f;  \/\/\u30ab\u30e1\u30e9\u3092X\u65b9\u5411\u306b\u56de\u8ee2\u3055\u305b\u308b\u89d2\u5ea6\r\n    private float currentY = 0.0f;  \/\/\u30ab\u30e1\u30e9\u3092Y\u65b9\u5411\u306b\u56de\u8ee2\u3055\u305b\u308b\u89d2\u5ea6\r\n\r\n    \/\/\u30ab\u30e1\u30e9\u56de\u8ee2\u7528\u4fc2\u6570(\u5024\u304c\u5927\u304d\u3044\u307b\u3069\u56de\u8ee2\u901f\u5ea6\u304c\u4e0a\u304c\u308b)\r\n    private float moveX = 4.0f;     \/\/\u30de\u30a6\u30b9\u30c9\u30e9\u30c3\u30b0\u306b\u3088\u308b\u30ab\u30e1\u30e9X\u65b9\u5411\u56de\u8ee2\u4fc2\u6570\r\n    private float moveY = 2.0f;     \/\/\u30de\u30a6\u30b9\u30c9\u30e9\u30c3\u30b0\u306b\u3088\u308b\u30ab\u30e1\u30e9Y\u65b9\u5411\u56de\u8ee2\u4fc2\u6570\r\n    private float moveX_QE = 2.0f;  \/\/QE\u30ad\u30fc\u306b\u3088\u308b\u30ab\u30e1\u30e9X\u65b9\u5411\u56de\u8ee2\u4fc2\u6570\r\n\r\n    void Start()\r\n    {\r\n\r\n    }\r\n\r\n    void Update()\r\n    {\r\n        \/\/Q\u3068E\u30ad\u30fc\u3067\u30ab\u30e1\u30e9\u56de\u8ee2\r\n        if (Input.GetKey(KeyCode.Q))\r\n        {\r\n            currentX += -moveX_QE;\r\n        }\r\n        if (Input.GetKey(KeyCode.E))\r\n        {\r\n            currentX += moveX_QE;\r\n        }\r\n\r\n        \/\/\u30de\u30a6\u30b9\u53f3\u30af\u30ea\u30c3\u30af\u3092\u62bc\u3057\u3066\u3044\u308b\u3068\u304d\u3060\u3051\u30de\u30a6\u30b9\u306e\u79fb\u52d5\u91cf\u306b\u5fdc\u3058\u3066\u30ab\u30e1\u30e9\u304c\u56de\u8ee2\r\n        if (Input.GetMouseButton(1))\r\n        {\r\n            currentX += Input.GetAxis(\"Mouse X\") * moveX;\r\n            currentY += Input.GetAxis(\"Mouse Y\") * moveY;\r\n            currentY = Mathf.Clamp(currentY, YAngle_MIN, YAngle_MAX);\r\n\r\n        }\r\n        distance = Mathf.Clamp(distance - Input.GetAxis(\"Mouse ScrollWheel\"), distance_min, distance_max);\r\n    }\r\n    void LateUpdate()\r\n    {\r\n        if (target != null)  \/\/target\u304c\u6307\u5b9a\u3055\u308c\u308b\u307e\u3067\u306e\u30a8\u30e9\u30fc\u56de\u907f\r\n        {\r\n            lookAt = target.position + offset;  \/\/\u6ce8\u8996\u5ea7\u6a19\u306ftarget\u4f4d\u7f6e+offset\u306e\u5ea7\u6a19\r\n\r\n            \/\/\u30ab\u30e1\u30e9\u65cb\u56de\u51e6\u7406\r\n            Vector3 dir = new Vector3(0, 0, -distance);\r\n            Quaternion rotation = Quaternion.Euler(-currentY, currentX, 0);\r\n\r\n            transform.position = lookAt + rotation * dir;   \/\/\u30ab\u30e1\u30e9\u306e\u4f4d\u7f6e\u3092\u5909\u66f4\r\n            transform.LookAt(lookAt);   \/\/\u30ab\u30e1\u30e9\u3092LookAt\u306e\u65b9\u5411\u306b\u5411\u3051\u3055\u305b\u308b\r\n        }\r\n\r\n    }\r\n\r\n}<\/pre>\n

Target\u306f\u5e38\u306b\u8996\u754c\u306e\u4e2d\u5fc3\u306b\u7f6e\u304d\u305f\u3044\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002<\/p>\n

\u3064\u307e\u308a\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092Target\u306b\u8a2d\u5b9a\u3059\u308b\u3053\u3068\u3067\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306b\u8ffd\u5f93\u3057\u3001\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u5468\u308a\u3092\u65cb\u56de\u3059\u308b\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3059\u3002<\/p>\n

\u3053\u306e\u30b9\u30af\u30ea\u30d7\u30c8\u3067\u306f\u30de\u30a6\u30b9\u306e\u53f3\u30af\u30ea\u30c3\u30af\u3092\u62bc\u3057\u306a\u304c\u3089\u30c9\u30e9\u30c3\u30b0\u3059\u308b\u3053\u3068\u3067\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u4e2d\u5fc3\u306b\u30ab\u30e1\u30e9\u3092\u65cb\u56de\u3055\u305b\u3001\u30de\u30a6\u30b9\u30db\u30a4\u30fc\u30eb\u306e\u56de\u8ee2\u3067\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3068\u306e\u8ddd\u96e2\u3092\u8abf\u7bc0\u3067\u304d\u308b\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n

\u5b9f\u969b\u306b\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3068\u30ab\u30e1\u30e9\u3092\u52d5\u304b\u3057\u3066\u307f\u307e\u3057\u3087\u3046\uff01<\/h2>\n
<\/i>\"\"<\/a><\/div>\n

\u64cd\u4f5c\u65b9\u6cd5<\/h3>\n

\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3068\u306e\u8ddd\u96e2\u8abf\u6574\uff1a\u30de\u30a6\u30b9\u30db\u30a4\u30fc\u30eb<\/strong><\/p>\n

\u30ab\u30e1\u30e9\u65cb\u56de\uff1a[Q]\u30ad\u30fc or [E]\u30ad\u30fc\u3000\u307e\u305f\u306f\u3000\u30de\u30a6\u30b9\u53f3\u30af\u30ea\u30c3\u30af\uff06\u30c9\u30e9\u30c3\u30b0<\/strong><\/p>\n

\u30ab\u30e1\u30e9\u304c\u30e6\u30cb\u30c6\u30a3\u3061\u3083\u3093\u3092\u8ffd\u5c3e\u3057\u3066\u3044\u308b\u3053\u3068\u304c\u308f\u304b\u308a\u307e\u3059\u3002<\/p>\n

\u30e6\u30cb\u30c6\u30a3\u3061\u3083\u3093\u3092\u8210\u3081\u56de\u3059\u3088\u3046\u306b\u773a\u3081\u3066\u3001\u6c17\u304c\u6e08\u3093\u3060\u3089\u6b21\u306b\u884c\u304d\u307e\u3057\u3087\u3046\u3002<\/p>\n

\u6b21\u56de\u4e88\u544a\uff01<\/h2>\n

\u4eca\u56de\u30d7\u30ec\u30a4\u30e4\u30fc\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u304c\u52d5\u304f\u3053\u3068\u304c\u3067\u304d\u3001\u8996\u754c\u3082\u52d5\u304b\u3059\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\u3002<\/p>\n

\u7a7a\u9593\u306e\u306a\u304b\u3092\u81ea\u7531\u306b\u52d5\u304f\u3053\u3068\u304c\u3067\u304d\u308b\u3088\u3046\u306b\u306a\u308a\u307e\u3057\u305f\uff01<\/p>\n

\u30b2\u30fc\u30e0\u3089\u3057\u304f\u306a\u3063\u3066\u304d\u307e\u3057\u305f\u306d\uff01\uff01<\/p>\n

\u6b21\u56de\u306f\u30de\u30eb\u30c1\u30d7\u30ec\u30a4\u30aa\u30f3\u30e9\u30a4\u30f3\u306b\u5bfe\u5fdc\u3055\u305b\u3066\u3044\u304d\u307e\u3059\u3002<\/p>\n

\u304a\u697d\u3057\u307f\u306b\uff01\uff01<\/p>\n<\/div>","protected":false},"excerpt":{"rendered":"

\u30ab\u30e1\u30e9\u30aa\u30d6\u30b8\u30a7\u30af\u30c8 \u30ab\u30e1\u30e9\u306f\u30d7\u30ec\u30a4\u30e4\u30fc\u306e\u76ee\u3068\u306a\u308b\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u3067\u3059\u3002 \u57fa\u672c\u7684\u306b\u30b2\u30fc\u30e0\u306f\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u306e\u8996\u70b9\u306b\u306a\u308b\u4e00\u4eba\u79f0\u8996\u70b9\u304b\u3001\u5c11\u3057\u96e2\u308c\u305f\u3068\u3053\u308d\u304b\u3089\u81ea\u5206\u306e\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3092\u6620\u3059\u4e09\u4eba\u79f0\u8996\u70b9\u306e\u3069\u3061\u3089\u304b\u3067\u3059\u3002 \u4eca\u56de\u306f … <\/p>\n","protected":false},"author":1,"featured_media":188,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,3],"tags":[],"_links":{"self":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts\/159"}],"collection":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/comments?post=159"}],"version-history":[{"count":16,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts\/159\/revisions"}],"predecessor-version":[{"id":483,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/posts\/159\/revisions\/483"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/media\/188"}],"wp:attachment":[{"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/media?parent=159"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/categories?post=159"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/uniblo.biz\/wp-json\/wp\/v2\/tags?post=159"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}