//tips
嶋津様打ち合わせ
//Terrainのpaint detailsのheight変更
paint detailsで設置した草の高さがプレイヤーの視線より高かったため、detailsの高さを下げる方法を模索したら、TerrainのEdit detailsのEditからMax heightを変更できることわかり、これにより、素材は変えないまま草の高さを変えることができるようになった。
草および地面上のプレイヤーy座標は接地した状態で6から変化しなくなった。
//playerカメラの設定
フィールドを映すカメラではなく、プレイヤーの視点を映すカメラの配置も考える。
一人称は酔うのであまり好きではないので三人称でプレイヤーを追いかけるカメラを考えていく。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class EnvCameraFollow : MonoBehaviour
{
GameObject player;
Vector3 offset;
void Start()
{
player = GameObject.FindWithTag("Player");
}
void Update()
{
Vector3 pos = player.transform.localPosition;
offset = new Vector3(0,3,-7);
transform.localPosition = pos + offset;
}
}
Offsetで三人称カメラを設定すると、プレイヤーの向きを考慮せずに、一方向しか写せない。プレイヤーの子要素に入れると、方向転換の際のフレが大きくあまり適切でない。
下記のスクリプトでも試してみたがこれは一人称でしかうまく働かなく、プレイヤーの回転方向により、プレイヤーをカメラに映さなくなる状況が生じる。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Envcamerasmooth : MonoBehaviour
{
public Transform target;
public float smoothing = 5f;
private Vector3 offset;
void Start()
{
offset = transform.position - target.position;
}
void Update()
{
Vector3 targetCamPos = target.position + offset;
transform.position = Vector3.Lerp(
transform.position,
targetCamPos,
Time.deltaTime * smoothing
);
}
}
カメラの回転に影響を与えるプレイヤーの移動の方を考え直した方が良いかもしれない。
//photonのカウント同期問題の解決
先日苦戦したphotonのカウント同期問題が解決した。
まずは、photonviewをスクリプトで生成するプレイヤーのみにつけるのではなく、シーンに最初から設置されているUIボタンにphotonviewをつけることでカウント機能をプレイヤーから分離させた。
分離させたカウント機能ではRPCを使用し、各プレイヤーで同一の共通の値を持つことができるようにする。
さらに、クリック主をphotonismineではなくPhotonNetwork.LocalPlayer.UserIdで区別することにより、任意の値でのクリック者にUI表示をさせることができるようになった。
BeforeCount()をボタンのonclickに登録している。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class photonCount : MonoBehaviourPunCallbacks
{
[SerializeField]
NumberProp numberProp;
Getpnumber getpnumber;
int lobbyPlayerMaxCount;
public void BeforeCount()
{
photonView.RPC(nameof(LobbyCount), RpcTarget.AllViaServer, PhotonNetwork.LocalPlayer.UserId);
}
// [PunRPC]属性をつけると、RPCでの実行が有効になる
[PunRPC]
public void LobbyCount(string id)
{
lobbyPlayerMaxCount++;
Debug.Log(lobbyPlayerMaxCount);
Onflag(id);
}
public void Onflag(string id)
{
if (lobbyPlayerMaxCount == 2)
{
if (id == PhotonNetwork.LocalPlayer.UserId)
{
//numberProp = GameObject.FindWithTag("PlayerNumber").GetComponent<NumberProp>();
numberProp.Faceon();
}
//flag = false;
}
}
}