- Home /
Question by
NeoBossGaming · Apr 13 at 10:24 AM ·
multiplayerphoton
InvalidCastException: Specified cast is not valid.
using UnityEngine;
using Photon.Pun;
namespace Photer.Client.Spawning
{
public class PlayerSpawner : MonoBehaviourPunCallbacks
{
[SerializeField] private GameObject playerPrefab = null;
[SerializeField] private GameObject playerCamera = null;
[SerializeField] private Transform cam;
[SerializeField] private Transform playerPosition;
private float X;
private float Y;
public float Sensitivity;
void Awake()
{
Vector3 euler = transform.rotation.eulerAngles;
X = euler.x;
Y = euler.y;
}
private void Start()
{
var player = PhotonNetwork.Instantiate(playerPrefab.name, transform.position, Quaternion.identity);
var cam = UnityEngine.Object.Instantiate(playerCamera, playerPosition.position, Quaternion.identity);
}
private void Update()
{
const float MIN_X = 0.0f;
const float MAX_X = 360.0f;
const float MIN_Y = -90.0f;
const float MAX_Y = 90.0f;
X += Input.GetAxis("Mouse X") * (Sensitivity * Time.deltaTime);
if (X < MIN_X) X += MAX_X;
else if (X > MAX_X) X -= MAX_X;
Y -= Input.GetAxis("Mouse Y") * (Sensitivity * Time.deltaTime);
if (Y < MIN_Y) Y = MIN_Y;
else if (Y > MAX_Y) Y = MAX_Y;
cam.transform.rotation = Quaternion.Euler(Y, X, 0.0f);
cam.transform.position = playerPosition.position;
}
}
}
Comment
Please edit your post and add a description. just posting half an error message and code is not enough.
Always add the complete error message, specifically the line it points to. This is important.
Please also use the code formatting button next time.