「Unity/photon/pun2/rpc」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
ページの作成:「RpcViewScene.cs <pre> using UnityEngine; using Photon.Pun; public class RpcViewScene : MonoBehaviour { PhotonView photonView = null; void Awake() { photonView...」
 
編集の要約なし
 
11行目: 11行目:
}
}
void Start() {
void Start() {
// int ownerID = photonView.ownerId;
}
}
void Update() {
void Update() {

2021年8月11日 (水) 09:09時点における最新版

RpcViewScene.cs

using UnityEngine;
using Photon.Pun;

public class RpcViewScene : MonoBehaviour
{
	PhotonView  photonView    = null;
	void Awake() {
		photonView    = GetComponent<PhotonView>();
	}
	void Start() {
	}
	void Update() {
		if (Input.GetKeyDown (KeyCode.Space)) {
			SpaceKey ();
		}
		if (Input.GetKeyDown (KeyCode.LeftArrow)) {
			LeftArrowKey ();
		}
	}
	void SpaceKey()
	{
		photonView.RPC("CustomMethod", RpcTarget.All);
	}
	[PunRPC]
	private void CustomMethod() {
		Debug.Log ("CustomMethod");
	}
	void LeftArrowKey() {
		object[] args = new object[]{
			"hoge",
			new string[] {"taro", "jiro", "saburo"}
		};
		photonView.RPC("Custom2Method", RpcTarget.All, args);
	}
	[PunRPC]
	private void Custom2Method(string str, string[] names) {
		Debug.Log ("CustomMethod " + str);
		foreach (string name in names) {
			Debug.Log ("CustomMethod name=" + name);
		}
	}
}