現在Unityを使ってネットワークゲームを作っています。
以下のコードをスポーンするプレイヤーオブジェクトに添付してそのプレイヤーからそのオブジェクトの子としてタンクがスポーンするスクリプトを書いたのですが、うまく動きません。ホスト側でしかスポーンしないことや、二つスポーンしてしまうなどの不具合が起きます。どこを直せばいいでしょうか?
C#
1using UnityEngine; 2using System.Collections; 3using UnityEngine.Networking; 4 5public class Chooseplayer : NetworkBehaviour 6{ 7 public float chooseplayerscore = 1.0f; 8 public GameObject obj; 9 public Transform playerspown; 10 public GameObject playerTANK; 11 public float SCAD = 1.0f; 12 // Use this for initialization 13 void Start() 14 { 15 16 } 17 18 // Update is called once per frame 19 [Command] 20 void CmdSetup() 21 { 22 23 24 { 25 26 if (chooseplayerscore == 2.0f) 27 { 28 29 obj = (GameObject)Instantiate(playerTANK, playerspown.position, playerspown.rotation); 30 obj.transform.parent = playerspown.transform; 31 var PlayerPrefab = obj; 32 NetworkServer.Spawn(PlayerPrefab); 33 34 } 35 36 } 37 } 38 void Update() 39 { 40 if (isLocalPlayer) 41 { 42 43 44 45 if (SCAD == 1.0f) 46 { 47 48 if (true) 49 { 50 SCAD -= 1.0f; 51 CmdSetup(); 52 } 53 } 54 } 55} 56 57
あなたの回答
tips
プレビュー