「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時点における版
アバター風にしてみる
- Cube作成。ここでは"Avatar"いう名前に変更した。
- CubeにBoxColliderが追加されていることを確認
- CubeのAddComponentにPhotonAvaterと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;
}
}
}