//tips
//微調整
プレイヤー消滅を確認して生成されるGhostcameraの移動スクリプトを修正する。
現在は自身が向いている方向から左右前後へ移動できていないのでそちらの動きを可能にさせる。これは現在のプレイヤーの動きと同じ。
Photon同期・アニメーション設定も必要ないので下記の形でシンプルにした。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class GhostMove : MonoBehaviour
{
Rigidbody rb;
bool Inverseflag = true;
public float rabbitspeedup = 10;
float wolfspeed = 1;
void Start()
{
rb = GetComponent<Rigidbody>();
}
void FixedUpdate()
{
// Upキーで前に進む
if (Input.GetKey("up"))
{
Inverseflag = true;
Vector3 moveForward = transform.position + transform.forward * 100;
moveForward.y = 0;
rb.position = transform.position + transform.forward * 1.5f * Time.deltaTime * rabbitspeedup * wolfspeed;
}
// Downキーで後ろに進む
if (Input.GetKey("down"))
{
if (Inverseflag)
{
Vector3 moveForward = transform.position - transform.forward * 500;
moveForward.y = 0;
Quaternion targetRotation = Quaternion.LookRotation(moveForward);
transform.rotation = targetRotation;
Inverseflag = false;
}
rb.position = transform.position + transform.forward * 1.0f * Time.deltaTime * rabbitspeedup * wolfspeed;
}
//right キーで右に進む
if (Input.GetKey("right"))
{
Inverseflag = true;
Vector3 moveForward = transform.position + transform.right * 500;
moveForward.y = 0;
Quaternion targetRotation = Quaternion.LookRotation(moveForward);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 2 * Time.deltaTime);
rb.position = transform.position + transform.forward * 2.0f * Time.deltaTime * rabbitspeedup * wolfspeed;
}
//left キーで左に進む
if (Input.GetKey("left"))
{
Inverseflag = true;
Vector3 moveForward = transform.position - transform.right * 500;
moveForward.y = 0;
Quaternion targetRotation = Quaternion.LookRotation(moveForward);
transform.rotation = Quaternion.Slerp(transform.rotation, targetRotation, 2 * Time.deltaTime);
rb.position = transform.position + transform.forward * 2.0f * Time.deltaTime * rabbitspeedup * wolfspeed;
}
}
}
正常に機能した。
if (mycamera!=null)を付加し、プレイヤーが消滅した場合の対処として、HPUICameraLookatスクリプトの調整も行った。
また、時々、プレイヤーの方を向かないHPUIが存在するので要因を調べる。
全てのプレイヤーに組み込まれているカメラには生成主のみアクティブにするスクリプトが記載されているので基本的にシーンにはMainCameraは一つしか存在していないはず。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
public class Mycamornot : MonoBehaviourPunCallbacks
{
void Start()
{
if (photonView.IsMine)
{
this.gameObject.SetActive(true);
}
else
{
this.gameObject.SetActive(false);
}
}
}
自身のmycameraがオフになる前にHPUIの方でmycameraを取得してしまっているの可能性があるのでmycamera = GameObject.FindWithTag("MainCamera").GetComponent<Camera>();の処理を少し遅らせる方法を考える。
Camera側からfindの発生時点を指定して行わせるようにした。
if (photonView.IsMine)
{
this.gameObject.SetActive(true);
HPUICameraLookat.MyCamStart();
}
変更を加えたが生成プレイヤーの方にHPUIが向かないのでデバッグでどのカメラを取得しているかを確認する。
photonView.IsMineで判別しようとしているにもかかわらずphoton viewコンポーネントがカメラにアタッチされていなかった。
アタッチしたがそれでもログが出てこない。スクリプトを見直すとカメラコンポーネントを取得していたので、その必要ないのでオブジェクトとして取得した。
GameObject mycamera;
public void MyCamStart()
{
mycamera = GameObject.FindWithTag("MainCamera");
それでもUIが常にプレイヤーの方に向いて表示されない。こちら検証していく。