ãUnity9ãUNETã§æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ããï¼ãUNET8ã
Unity5.1.1p3 Personal(2015å¹´7æ)
前回の続きã§ãã
ä»åã¯æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ãã¦ããã¾ãã
å®éã«ã¯ãã¡ã¼ã¸ãä¸ããå段éã¨ãã¦ãæµãã¬ã¤ã¤ã¼ã®ååãåå¾ããã¨ããã¾ã§é²ãã¾ãã
UNET Part 8 - Shooting - YouTube
ãç®æ¨ãæµãã¬ã¤ã¤ã¼ã®ååãåå¾ãã
â æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ããç®çã®ã¹ã¯ãªããä½æ
ã¾ãã¯ã¹ã¯ãªãããä½æãã¦ããã¾ãã
Player_Shootingã¨ããååã®ã¹ã¯ãªãããæ°è¦ä½æããPlayerãã¬ããã«åãä»ãã¦ä¸ããã
using UnityEngine; using System.Collections; using UnityEngine.Networking; public class Player_Shooting : NetworkBehaviour { private float damage = 25; //ãã¡ã¼ã¸é private float range = 200; //Raycastã®è·é¢ //FirstPersonCharacterãæå® [SerializeField] private Transform camTransform; private RaycastHit hit; void Update () { CheckIfShooting(); } void CheckIfShooting () { if (!isLocalPlayer) { return; } if (Input.GetKeyDown(KeyCode.Mouse0)) { Shooting(); } } void Shooting () { //ã«ã¡ã©ã®åæ¹ã«Raycastãé£ã°ã //TransformPoint: æå®ããåã ã座æ¨ãããã if (Physics.Raycast (camTransform.TransformPoint (0, 0, 0.5f), camTransform.forward, out hit, range)) { Debug.Log (hit.transform.tag); //RaycastãPlayerã¨è¡çªããæ if (hit.transform.tag == "Player") { //ååãåå¾ string uIdentity = hit.transform.name; //ååã¨ãã¡ã¼ã¸éãå¼æ°ã«ã¡ã½ããå®è¡ CmdTellServerWhoWasShot(uIdentity, damage); } } } //Command: SyncVarå¤æ°ã®å¤æ´çµæããå ¨ã¯ã©ã¤ã¢ã³ãã¸éä¿¡ [Command] void CmdTellServerWhoWasShot (string uniqueID, float dmg) { //æµãã¬ã¤ã¤ã¼ã®ååã§GameObjectãåå¾ GameObject go = GameObject.Find(uniqueID); //Apply damage to that player } }
Player_Shooting.cs
ã¾ãã¯SerializeFieldå¤æ°ã§ããcamTransformã¸ãFirstPersonCharacterãæå®ãã¾ãã
ç¶ãã¦Playerã¿ã°ãPlayerãã¬ããã«åãä»ãã¾ãããã
Playerãã¬ããã®Inspectorãã¥ã¼ãããTag > Playeré¸æ
ç»é¢ãã¯ãªãã¯ããæã«Shootingã¡ã½ãããå¼ã³ãã«ã¡ã©åæ¹ã«Laycastãé£ã°ããLaycastä¸ã«Playerã¿ã°ã®ã¤ãããªãã¸ã§ã¯ããåå¨ããå ´åååãåå¾ããååã¨ãã¡ã¼ã¸éãå¼æ°ã«CmdTellServerWhoWasShotã¡ã½ãããå¼ãã§ãã¾ãã
CmdTellServerWhoWasShotã¡ã½ããã§ã¯ä»ã®ã¨ãããåå¾ããååãå
ã«GameObjectãåå¾ãã¦ããã ãã§ãã
次å以éã§å®éã«ãã¡ã¼ã¸ãä¸ãã¦ããã¨æããã¾ãã
â¡ç»é¢ã«ç §æºã表示ããã
ä»ã®ã¾ã¾ã§ãç»é¢ä¸å¤®ã«Playerãæ¥ãæã«ç»é¢ãã¯ãªãã¯ããã°ãCmdTellServerWhoWasShotã¡ã½ãããå®è¡ã§ãã¾ãããæµPlayerãç»é¢ä¸å¤®ã«æ¥ãã®ãåãããããããã«ç §æºã表示ãã¾ãã
ã¾ãã¯Imageãªãã¸ã§ã¯ããä½æãã¾ããHierarchyãã¥ã¼ããCreate > UI > Imageãé¸æãã¾ãã
Anchor Presetãcenter - middleã«ããWidthã¨Heightããããã4ã«è¨å®ãã¾ããã¾ããImageã®Colorã赤ã«ãã¾ãã
Imageã®è¨å®
ç»é¢ä¸å¤®ã«ç
§æºã表示
ãã®èµ¤ç¹ã«æµPlayerãéãªã£ãæã«ç»é¢ãã¯ãªãã¯ããã°ãCmdTellServerWhoWasShotã¡ã½ãããå®è¡ãããã¨ãã§ãã¾ãã
â¢çµæ
ç
§æºãåããã¦ã¯ãªãã¯ï¼
Playerã¿ã°åå¾ï¼
ä»åã¯ããã¾ã§ã§ãã
ãããã¨ããããã¾ããã
ãUnity9ãUNETã§ãã«ããã¬ã¤ã¤ã¼ãªãªã³ã©ã¤ã³ã²ã¼ã éçºãUNET1ã
ãUnity9ãUNETã§ãã¬ã¤ã¤ã¼ã®åããè£éãããªããããªåããå®ç¾ãããUNET1-2ã
ãUnity9ãUNETã§ãããã¯ã¼ã¯è¶ãã«å¾ã(Rotation)ãåæããããUNET2ã
ãUnity9ãUNETã§ãªã³ã©ã¤ã³éå§æã®ãã¬ã¤ã¤ã¼çæä½ç½®ãå¤æ´ãããUNET2-2ã
ãUnity9ãUNETã®ãããã¯ã¼ã¯ãã©ãã£ãã¯ã軽æ¸ããå¹çåãããUNET3ã
ãUnity9ãUNETã®latency(é
延æé)ãæ¹åãããUNET4ã
ãUnity9ãUNETã®latency(é
延æé)ã表示ãã¦ãã¡ãã£ã¨ã ãæ¹åãããUNET4-2ã
ãUnity9ãUNETã®SyncVarã®hookã®ä½¿ç¨ä¾ã¨ãåæ代ã®åææ¹æ³ãUNET5ã
ãUnity9ãUNETã使ã£ã¦RotationãåæããããUNET6ã
ãUnity9ãUNETã§åãã¬ã¤ã¤ã¼ã«PlayerIDãè¨å®ãããUNET7ã
ãUnity9ãUNETã§æµãã¬ã¤ã¤ã¼ã«ãã¡ã¼ã¸ãä¸ããï¼ãUNET8ã
ãUnity9ãUNETã§HPãç»é¢ã«è¡¨ç¤ºããPlayerã¸ãã¡ã¼ã¸ãä¸ãããUNET9ã
ãUnity9ãUNETã§HPã0以ä¸ã«ãªã£ãæãPlayerãç ´å£ããï¼ãUNET10ã
ãUnity9ãUNETã§æ»ãã Playerãçãè¿ãããï¼ãUNET11ã
ãUnity9ãUNETã§ã¾ã³ãAIãåºç¾ãããï¼ãUNET12ã
ãUnity9ãUNETã§ã¾ã³ãçææã«ã¦ãã¼ã¯ãªIDãä»ããï¼ãUNET13ã
ãUnity9ãUNETã§ã¾ã³ããæã¤ï¼ãUNET14ã
ãUnity9ãUNETã§ã¾ã³ãã«æ»æãããï¼ãUNET15ã
ãUnity9ãUNETã§ã¾ã³ãã®åããã¹ã ã¼ãºã«ã·ã³ã¯ããããï¼ãUNET16ã
ãUnity9ãUNETã§ã¾ã³ãçºçå°ç¹ãå¢ãããUNET17ã
ãUnity9ãUNETã§çºçãããã°ãåãé¤ããUNET18ã
ãUnity9ãUnity MultiPlayerã使ã£ã¦ãããã¯ã¼ã¯è¶ãã«ãããã¡ã¤ãã³ã°ï¼ãUNET19ã
ãUnity9ãGUIãæ¹åãã¦ãNetwork Managerãè¦ãããããï¼ãUNET20ã
ãUnity9ã表示ããGUI(Network Manager)ãæ©è½ãããï¼ãUNET20-2ã
ãUnity9ãUNETã§Animationãåæãããï¼ãUNET21ã