\u30ab\u30e1\u30e9\u304b\u3089\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u304c\u3042\u308b\u65b9\u5411\u306bRay\u3092\u98db\u3070\u3057\u3001Ray\u304c\u5f53\u305f\u3063\u305f\u5834\u6240\u306b\u30ab\u30fc\u30bd\u30eb\u3092\u52d5\u304b\u3059\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
\u666e\u901a\u306e\u30b2\u30fc\u30e0\u3067\u306f\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u3084\u653b\u6483\u306b\u30ab\u30fc\u30bd\u30eb\u306f\u4e57\u3089\u306a\u3044\u306e\u3067\u3001layerMask\u3067User Layer 8\u306e”Player”\u30ec\u30a4\u30e4\u30fc\u3068User Layer 9\u306e\u201dAttack\u201d\u30ec\u30a4\u30e4\u30fc\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306b\u306fRay\u304c\u5f53\u305f\u3089\u306a\u3044\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n
\u306a\u306e\u3067\u30d7\u30ec\u30a4\u30e4\u30fc\u3068\u653b\u6483\u306e\u30aa\u30d6\u30b8\u30a7\u30af\u30c8\u306e\u30ec\u30a4\u30e4\u30fc\u304c\u9055\u3046\u756a\u53f7\u3067\u3042\u308c\u3070layerMask\u306e\u6570\u5b57\u3092\u66f8\u304d\u63db\u3048\u3066\u304f\u3060\u3055\u3044\u3002<\/p>\n
CharacterControlScript.cs\u306e\u5909\u66f4\u5f8c\u30bd\u30fc\u30b9\u30b3\u30fc\u30c9<\/h3>\nusing 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(inspecter\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 \/\/\u6226\u95d8\u7528\u5909\u6570\uff06\u72b6\u614b\u30d5\u30e9\u30b0\u7ba1\u7406\r\n public GameObject BallPrefab; \/\/\u30dc\u30fc\u30ebPrefab\r\n bool MoveLock = false; \/\/\u79fb\u52d5\u30ed\u30c3\u30af\u30d5\u30e9\u30b0\r\n bool AttackLock = false; \/\/\u9023\u5c04\u9632\u6b62\u7528\u653b\u6483\u30ed\u30c3\u30af\u30d5\u30e9\u30b0\r\n bool invincible = false; \/\/\u7121\u6575\u30d5\u30e9\u30b0\r\n bool Deadflag = false; \/\/\u6b7b\u4ea1\u30d5\u30e9\u30b0\r\n\r\n \/\/\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u306e\u4f4d\u7f6e\u53d6\u5f97\u7528\r\n Transform Cursor;\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 \/\/\u30de\u30a6\u30b9\u30ab\u30fc\u30bd\u30eb\u306eTransform\u3092\u8a2d\u5b9a\r\n Cursor = GameObject.Find(\"MouseCursor\").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 \/\/\u81ea\u30ad\u30e3\u30e9\u3067\u306a\u3051\u308c\u3070\u64cd\u4f5c\u3057\u306a\u3044\u305f\u3081return\r\n if (!myPV.isMine)\r\n {\r\n return;\r\n }\r\n\r\n \/\/\u79fb\u52d5\u30ed\u30c3\u30afON\u307e\u305f\u306f\u6b7b\u4ea1\u30d5\u30e9\u30b0ON\u3067\u3042\u308c\u3070\u79fb\u52d5\u3001\u653b\u6483\u3092\u3055\u305b\u306a\u3044\r\n if (!MoveLock && !Deadflag)\r\n {\r\n moveControl(); \/\/\u79fb\u52d5\u7528\u95a2\u6570\r\n RotationControl(); \/\/\u65cb\u56de\u7528\u95a2\u6570\r\n }\r\n\r\n \/\/\u653b\u6483\u30ed\u30c3\u30af\u304c\u304b\u304b\u3063\u3066\u3044\u306a\u3051\u308c\u3070\u653b\u6483\u3067\u304d\u308b\r\n if (!AttackLock)\r\n {\r\n \/\/\u653b\u6483\u51e6\u7406\r\n AttackControl();\r\n }\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\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 }\r\n\r\n void moveControl()\r\n {\r\n \/\/\u2605\u9032\u884c\u65b9\u5411\u8a08\u7b97\r\n \/\/\u30ad\u30fc\u30dc\u30fc\u30c9\u5165\u529b\u3092\u53d6\u5f97\r\n float v = Input.GetAxisRaw(\"Vertical\"); \/\/\u2191\u2193\u306e\u5165\u529b \r\n float h = Input.GetAxisRaw(\"Horizontal\"); \/\/\u2190\u2192\u306e\u5165\u529b \r\n\r\n \/\/\u30ab\u30e1\u30e9\u306e\u6b63\u9762\u65b9\u5411\u30d9\u30af\u30c8\u30eb\u304b\u3089Y\u6210\u5206\u3092\u9664\u304d\u3001\u6b63\u898f\u5316\u3057\u3066\u30ad\u30e3\u30e9\u304c\u8d70\u308b\u65b9\u5411\u3092\u53d6\u5f97\r\n Vector3 forward = Vector3.Scale(Camera.main.transform.forward, new Vector3(1, 0, 1)).normalized; \r\n Vector3 right = Camera.main.transform.right; \/\/\u30ab\u30e1\u30e9\u306e\u53f3\u65b9\u5411\u3092\u53d6\u5f97\r\n\r\n \/\/\u30ab\u30e1\u30e9\u306e\u65b9\u5411\u3092\u8003\u616e\u3057\u305f\u30ad\u30e3\u30e9\u306e\u9032\u884c\u65b9\u5411\u3092\u8a08\u7b97\r\n targetDirection = h * right + v * forward;\r\n\r\n \/\/\u2605\u5730\u4e0a\u306b\u3044\u308b\u5834\u5408\u306e\u51e6\u7406\r\n if (controller.isGrounded) \r\n {\r\n \/\/\u79fb\u52d5\u306e\u30d9\u30af\u30c8\u30eb\u3092\u8a08\u7b97\r\n moveDirection = targetDirection*speed;\r\n\r\n \/\/Jump\u30dc\u30bf\u30f3\u3067\u30b8\u30e3\u30f3\u30d7\u51e6\u7406\r\n if (Input.GetButton(\"Jump\")) \r\n {\r\n moveDirection.y = jumpSpeed;\r\n }\r\n }\r\n else \/\/\u7a7a\u4e2d\u64cd\u4f5c\u306e\u51e6\u7406\uff08\u91cd\u529b\u52a0\u901f\u5ea6\u7b49\uff09\r\n {\r\n float tempy = moveDirection.y;\r\n \/\/(\u2193\u306e\uff12\u6587\u306e\u51e6\u7406\u304c\u3042\u308b\u3068\u7a7a\u4e2d\u3067\u3082\u5165\u529b\u65b9\u5411\u306b\u52d5\u3051\u308b\u3088\u3046\u306b\u306a\u308b)\r\n \/\/moveDirection = Vector3.Scale(targetDirection, new Vector3(1, 0, 1)).normalized;\r\n \/\/moveDirection *= speed;\r\n moveDirection.y = tempy - gravity * Time.deltaTime;\r\n }\r\n\r\n \/\/\u2605\u8d70\u884c\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u7ba1\u7406\r\n if (v > .1 || v < -.1 || h > .1 || h < -.1) \/\/(\u79fb\u52d5\u5165\u529b\u304c\u3042\u308b\u3068)\r\n {\r\n animator.SetFloat(\"Speed\", 1f); \/\/\u30ad\u30e3\u30e9\u8d70\u884c\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3ON\r\n }\r\n else \/\/(\u79fb\u52d5\u5165\u529b\u304c\u7121\u3044\u3068)\r\n {\r\n animator.SetFloat(\"Speed\", 0f); \/\/\u30ad\u30e3\u30e9\u8d70\u884c\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3OFF\r\n }\r\n }\r\n\r\n void RotationControl() \/\/\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u304c\u79fb\u52d5\u65b9\u5411\u3092\u5909\u3048\u308b\u3068\u304d\u306e\u51e6\u7406\r\n {\r\n Vector3 rotateDirection = moveDirection;\r\n rotateDirection.y = 0;\r\n\r\n \/\/\u305d\u308c\u306a\u308a\u306b\u79fb\u52d5\u65b9\u5411\u304c\u5909\u5316\u3059\u308b\u5834\u5408\u306e\u307f\u79fb\u52d5\u65b9\u5411\u3092\u5909\u3048\u308b\r\n if (rotateDirection.sqrMagnitude > 0.01)\r\n {\r\n \/\/\u7de9\u3084\u304b\u306b\u79fb\u52d5\u65b9\u5411\u3092\u5909\u3048\u308b\r\n float step = rotateSpeed * Time.deltaTime;\r\n Vector3 newDir = Vector3.Slerp(transform.forward, rotateDirection, step);\r\n transform.rotation = Quaternion.LookRotation(newDir);\r\n }\r\n }\r\n\r\n \/\/\u30dc\u30fc\u30eb\u653b\u6483\r\n void AttackControl()\r\n {\r\n if (Input.GetButtonDown(\"Fire1\"))\r\n {\r\n \/\/\u30ab\u30fc\u30bd\u30eb\u65b9\u5411\u306b\u5411\u304f\r\n transform.LookAt(Cursor);\r\n\r\n \/\/\u653b\u6483\u30ed\u30c3\u30af\u958b\u59cb\r\n AttackLock = true;\r\n StartCoroutine(_ballattack(1f));\r\n }\r\n }\r\n\r\n IEnumerator _ballattack(float pausetime)\r\n {\r\n \/\/RPC\u3067\u30dc\u30fc\u30eb\u751f\u6210\r\n myPV.RPC(\"BallInst\", PhotonTargets.AllViaServer, transform.position + transform.up, transform.rotation);\r\n \/\/\u653b\u6483\u786c\u76f4\u306e\u305f\u3081pausetime\u3060\u3051\u5f85\u3064\r\n yield return new WaitForSeconds(pausetime);\r\n \/\/\u653b\u6483\u30ed\u30c3\u30af\u89e3\u9664\r\n AttackLock = false;\r\n }\r\n\r\n [PunRPC]\/\/\u30dc\u30fc\u30eb\u751f\u6210\r\n void BallInst(Vector3 instpos, Quaternion instrot, PhotonMessageInfo info)\r\n {\r\n \/\/\u30dc\u30fc\u30eb\u3092\u751f\u6210\r\n GameObject Ball = Instantiate(BallPrefab, instpos, instrot) as GameObject;\r\n Ball.GetComponent<BallManageScript>().Attacker = info.sender; \/\/\u30dc\u30fc\u30eb\u306b\u81ea\u5206\u306ePhotonPlayer\u60c5\u5831\u3092\u4e57\u305b\u308b\r\n }\r\n\r\n #region \u88ab\u5f3e\u95a2\u9023\u51e6\u7406\r\n void OnTriggerEnter(Collider col)\r\n {\r\n \/\/\u81ea\u30ad\u30e3\u30e9\u4ee5\u5916\u306a\u3089\u51e6\u7406\u3057\u306a\u3044\r\n if (!myPV.isMine)\r\n {\r\n return;\r\n }\r\n\r\n if (Deadflag || invincible) \/\/\u6b7b\u4ea1\u6642\u307e\u305f\u306f\u7121\u6575\u6642\u306f\u51e6\u7406\u3057\u306a\u3044\r\n {\r\n return;\r\n }\r\n \r\n PhotonPlayer colAttacker = col.GetComponent<BallManageScript>().Attacker;\r\n\r\n \/\/\u5f53\u305f\u3063\u305f\u7269\u304c\u30dc\u30fc\u30eb\u3067\u306f\u306a\u3044\u307e\u305f\u306f\u81ea\u5206\u304c\u751f\u6210\u3057\u305f\u30dc\u30fc\u30eb\u306a\u3089\u306a\u306b\u3082\u3057\u306a\u3044\r\n if (!col.CompareTag(\"Ball\")||colAttacker.IsLocal) \r\n {\r\n return;\r\n }\r\n else\r\n {\r\n \/\/\u30c0\u30e1\u30fc\u30b8\u3092\u4e0e\u3048\u308b\r\n LocalVariables.currentHP -= 20;\r\n\r\n \/\/\u653b\u6483\u5074\u30d7\u30ec\u30a4\u30e4\u30fc\u306ekillcount++\u51e6\u7406\r\n if (LocalVariables.currentHP > 0)\r\n {\r\n myPV.RPC(\"Damaged\", PhotonTargets.AllViaServer); \/\/\u88ab\u5f3e\u51e6\u7406RPC\r\n StartCoroutine(_rigor(.5f)); \/\/\u88ab\u5f3e\u786c\u76f4\u51e6\u7406\r\n }\r\n else\r\n {\r\n myPV.RPC(\"Dead\", PhotonTargets.AllViaServer); \/\/\u6b7b\u4ea1\u51e6\u7406RPC\r\n StartCoroutine(_revive(3.5f)); \/\/\u5fa9\u6d3b\u51e6\u7406\r\n }\r\n }\r\n }\r\n\r\n \/\/\u88ab\u5f3e\u51e6\u7406\u540c\u671f\u7528RPC\r\n [PunRPC]\r\n void Damaged()\r\n {\r\n \r\n MoveLock = true; \/\/\u786c\u76f4\u306e\u305f\u3081\u79fb\u52d5\u30ed\u30c3\u30afON\r\n animator.SetTrigger(\"DamagedTrigger\"); \/\/\u30c0\u30e1\u30fc\u30b8\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\r\n }\r\n\r\n \/\/\u30d2\u30c3\u30c8\u6642\u786c\u76f4\u51e6\u7406\r\n IEnumerator _rigor(float pausetime)\r\n {\r\n yield return new WaitForSeconds(pausetime); \/\/\u5012\u308c\u3066\u3044\u308b\u6642\u9593\r\n MoveLock = false; \/\/\u79fb\u52d5\u30ed\u30c3\u30af\u89e3\u9664\r\n }\r\n\r\n \/\/\u6b7b\u4ea1\u51e6\u7406\u540c\u671f\u7528RPC\r\n [PunRPC]\r\n void Dead()\r\n {\r\n Deadflag = true; \/\/\u6b7b\u4ea1\u30d5\u30e9\u30b0ON\r\n AttackLock = true; \/\/\u653b\u6483\u30ed\u30c3\u30afON\r\n MoveLock = true; \/\/\u79fb\u52d5\u30ed\u30c3\u30afON\r\n animator.SetTrigger(\"DeathTrigger\"); \/\/\u6b7b\u4ea1\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3ON\r\n }\r\n\r\n \/\/\u5fa9\u6d3b\u30b3\u30eb\u30fc\u30c1\u30f3\r\n IEnumerator _revive(float pausetime)\r\n {\r\n yield return new WaitForSeconds(pausetime); \/\/\u5012\u308c\u3066\u3044\u308b\u6642\u9593\r\n \/\/\u5fa9\u6d3b\r\n Deadflag = false; \/\/\u6b7b\u4ea1\u89e3\u9664\r\n AttackLock = false; \/\/\u653b\u6483\u30ed\u30c3\u30af\u89e3\u9664\r\n MoveLock = false; \/\/\u79fb\u52d5\u30ed\u30c3\u30af\u89e3\u9664\r\n invincible = true; \/\/\u6b7b\u4ea1\u5f8c\u7121\u6575\u958b\u59cb\r\n LocalVariables.currentHP = 100; \/\/HP\u56de\u5fa9\r\n yield return new WaitForSeconds(5f); \/\/\u6b7b\u4ea1\u5f8c\u7121\u6575\u6642\u9593\r\n invincible = false; \/\/\u7121\u6575\u89e3\u9664\r\n }\r\n #endregion\r\n}<\/pre>\nCharacterControlScript.cs\u81ea\u4f53\u304c\u9577\u304f\u306a\u3063\u3066\u304d\u3066\u3084\u3084\u3053\u3057\u304f\u601d\u3046\u304b\u3082\u3057\u308c\u307e\u305b\u3093\u304c\u3001\u4eca\u56de\u8ffd\u52a0\u3057\u305f\u30b9\u30af\u30ea\u30d7\u30c8\u306f\u30de\u30fc\u30af\u3055\u308c\u3066\u3044\u308b6\u884c\u306e\u307f<\/strong>\u3067\u3059\u3002<\/p>\n\u30ab\u30fc\u30bd\u30eb\u306eTransform\u3092\u5e38\u306b\u53d6\u5f97\u3057\u3066\u304a\u304d\u3001\u653b\u6483\u6642\u306b\u30ab\u30fc\u30bd\u30eb\u306ePosition\u306e\u65b9\u5411\u3092\u30ad\u30e3\u30e9\u30af\u30bf\u30fc\u304c\u5411\u304f\u3088\u3046\u306b\u3057\u3066\u3044\u307e\u3059\u3002<\/p>\n