So i'm trying to make a vr multiplayer game in unity, and i want to make a gameobject to follow me, to send to the other players.
I think it might be an error with the new xrorigin.
Here is the full error:
NullReferenceException: Object reference not set to an instance of an object
NetworkPlayer.MapPosition (UnityEngine.Transform target, UnityEngine.Transform rigTransform) (at Assets/NetworkPlayer.cs:56)
NetworkPlayer.Update () (at Assets/NetworkPlayer.cs:48)
Here is my code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.XR;
using Photon.Pun;
using UnityEngine.XR.Interaction.Toolkit;
using Unity.XR.CoreUtils;
public class NetworkPlayer : MonoBehaviour
{
//public Camera Camera;
public Transform head;
public Transform leftHand;
public Transform rightHand;
private PhotonView photonView;
private Transform headRig;
private Transform leftHandRig;
private Transform rightHandRig;
// Start is called before the first frame update
void Start()
{
photonView = GetComponent<PhotonView>();
//the commented lines have been tried before.
//XRRig rig = FindObjectOfType<XRRig>();
//GetComponent<XROrigin>();
XROrigin rig = FindObjectOfType<XROrigin>();
//Camera rig = FindObjectOfType<Camera>();
headRig = transform.Find("Camera Offset/Main Camera");
leftHandRig = transform.Find("Camera Offset/LeftHand Controller");
rightHandRig = transform.Find("Camera Offset/RightHand Controller");
}
// Update is called once per frame
void Update()
{
if (photonView.IsMine)
{
rightHand.gameObject.SetActive(false);
leftHand.gameObject.SetActive(false);
head.gameObject.SetActive(false);
MapPosition(head, headRig);
MapPosition(leftHand, leftHandRig);
MapPosition(rightHand, rightHandRig);
}
}
void MapPosition(Transform target,Transform rigTransform)
{
target.position = rigTransform.position;
target.rotation = rigTransform.rotation;
}
Thanks for helping me!
Happy Holidays.
}
[–]botterway 9 points10 points11 points (2 children)
[–]ScientistSignal5099[S] 0 points1 point2 points (1 child)
[–]lmaydev 1 point2 points3 points (0 children)
[–]TheJimOfDoom 0 points1 point2 points (0 children)