「Unity/photon/pun2/位置同期」の版間の差分

提供: 初心者エンジニアの簡易メモ
ナビゲーションに移動 検索に移動
ページの作成:「==アバター風にしてみる== #Cube作成。ここでは"Avatar"いう名前に変更した。 #CubeにBoxColliderが追加されていることを確認 #CubeのAdd...」
 
20行目: 20行目:
void Awake() {
void Awake() {
this.name = "Cube"+GetComponent<PhotonView> ().InstantiationId;
this.name = "Cube"+GetComponent<PhotonView> ().InstantiationId;
if (GetComponent<PhotonView> ().IsMine) {
if (GetComponent<PhotonView>().IsMine) {
GetComponent<Renderer> ().material.color = Color.red;
GetComponent<Renderer>().material.color = Color.red;
}
}
}
}
}
}
</pre>
</pre>

2022年12月7日 (水) 07:28時点における版

アバター風にしてみる

  1. Cube作成。ここでは"Avatar"いう名前に変更した。
  2. CubeにBoxColliderが追加されていることを確認
  3. CubeのAddComponentにPhotonAvaterと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;
		}
	}
}