私は今Unityでボードゲームの作成をしております。オフラインで動くようになったため、Photonを用いてオンライン対戦をできるようにしたいと思っています。
しかし、プレファブの生成が行えず困っています。エラーを見る限りでは「ゲームオブジェクトをスクリプト型に変換できない」と言われているのですが、型の宣言はしっかり行なっていますし、プレファブもUnityのResources直下にセットしています。もちろんPhotonViewコンポーネントもつけています。
一体何がいけないのでしょうか。
C#
1using System.Collections; 2using System.Collections.Generic; 3using UnityEngine; 4using Photon.Pun; 5using Photon.Realtime; 6 7public class NetGameMaster : MonoBehaviourPunCallbacks 8{ 9 protected int turn = 0; 10 protected GameObject gameboard; 11 protected GameBoard board; 12 protected Piece[] pl = new Piece[2]; 13 protected GameObject Piece1; 14 protected Piece piece1; 15 protected GameObject Piece2; 16 protected Piece piece2; 17 protected string faze; 18 19 // Start is called before the first frame update 20 public void Start() 21 { 22 //盤の作成 23 gameboard = GameObject.Find("GameBoard"); 24 board = gameboard.GetComponent<GameBoard>(); 25 //コマの配置 26Piece1 = PhotonNetwork.Instantiate((GameObject)Resources.Load ("Piece"),new Vector3(3,1,0),Quaternion.identity); 27 piece1 = Piece1.GetComponent<Piece>(); 28 piece1.FirstSet(3,0,0); 29 pl[0] = piece1; 30 31 Piece2 = PhotonNetwork.Instantiate((GameObject)Resources.Load ("Piece2"),new Vector3(2,1,5),Quaternion.identity); 32 piece2 = Piece2.GetComponent<Piece>(); 33 piece2.FirstSet(2,5,1); 34 pl[1] = piece2; 35 faze = "piece"; 36 37 } 38}
エラーは下記です。
Error
1Assets/Scripts/NetGameMaster.cs(26,42): error CS1503: Argument 1: cannot convert from 'UnityEngine.GameObject' to 'string' 2 3Assets/Scripts/NetGameMaster.cs(32,42): error CS1503: Argument 1: cannot convert from 'UnityEngine.GameObject' to 'string'
26行目は「Piece1 = PhotonNetwork.Instantiate((GameObject)Resources.Load ("Piece"),new Vector3(3,1,0),Quaternion.identity);」
32行目は「Piece2 = PhotonNetwork.Instantiate((GameObject)Resources.Load ("Piece2"),new Vector3(2,1,5),Quaternion.identity);」です。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。