「Unity/photon/pun2/位置同期」の版間の差分
ナビゲーションに移動
検索に移動
編集の要約なし |
|||
| 26行目: | 26行目: | ||
} | } | ||
</pre> | </pre> | ||
公式:https://doc.photonengine.com/ja-jp/pun/v2/gameplay/instantiation | |||
2022年12月7日 (水) 08:08時点における版
アバター風にしてみる
- Cube作成。ここでは"Avatar"いう名前に変更した。
- CubeにBoxColliderが追加されていることを確認
- CubeのAddComponentにPhotonAvaterとPhotonViewとPhotonTransformViewを追加
- CubeをPrefabに追加
- 以下スクリプトで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