facebook twitter hatena line email

Unity/photon/pun2/位置同期

提供: 初心者エンジニアの簡易メモ
2022年12月7日 (水) 17:08時点におけるAdmin (トーク | 投稿記録)による版

移動: 案内検索

アバター風にしてみる

  1. Cube作成。ここでは"Avatar"いう名前に変更した。
  2. CubeにBoxColliderが追加されていることを確認
  3. CubeのAddComponentにPhotonAvaterとPhotonViewとPhotonTransformViewを追加
  4. CubeをPrefabに追加
  5. 以下スクリプトでPrefabのAvaterをロードする。
  • PhotonManager.cs
GameObject avater = PhotonNetwork.Instantiate("Avater",  Vector3.zero, Quaternion.Euler(Vector3.zero),0);
  • PhotonAvater.sc
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System;
public class PhotonAvater : MonoBehaviourPunCallbacks {
	public string str = "guest1";
	void Awake() {
		this.name = "Cube"+GetComponent<PhotonView> ().InstantiationId;
		if (GetComponent<PhotonView>().IsMine) {
			GetComponent<Renderer>().material.color = Color.red;
		}
	}
}

公式:https://doc.photonengine.com/ja-jp/pun/v2/gameplay/instantiation