Access to third party controller scripts for Photon player instantiation
The whole answer can be found below.
Try Our
Documentation
Please check if you can find an answer in our extensive documentation on PUN.
Join Us
on Discord
Meet and talk to our staff and the entire Photon-Community via Discord.
Read More on
Stack Overflow
Find more information on Stack Overflow (for Circle members only).
Access to third party controller scripts for Photon player instantiation
LokimotiveUK
2020-03-14 08:41:39
Hey guys! I'm having some issues with getting the movement controller and input scripts referenced correctly in a PlayerSetup script that I am using to instantiate players in my multiplayer game in Unity. I'm learning here, so please go easy. Here's where I am:
I spent a lot of time today redoing the movement and animation on my own rigged model and adjusting everything so player movement and camera tracking are working, and its looking really good! The only thing left to do is to let each player take control of their character when they enter the multiplayer state, but currently each login controls all characters in the scene. As the movement scripts are separate from the ones in the standard Unity Assets and any Photon tutorials I have tried, I am unsure how to reference them correctly in the PlayerSetup script to the Invector VThirdPersonController and VThirdPersonInput scripts. I have tried to reference them in the PlayerSetup script as below as well as adding in control of the camera which is also from the installed asset, vThirdPersonCamera (currently a variant of the original package prefab).
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using TMPro;
public class PlayerSetup : MonoBehaviourPunCallbacks
{
[SerializeField]
TextMeshProUGUI playerNameText;
[SerializeField]
GameObject PlayerCamera;
//VThirdPersonController thirdPersonController = GameObject.GetComponent<VThirdPersonController>();
//VThirdPersonInput thirdPersonInput = GameObject.GetComponent<VThirdPersonInput>();
//GameObject thirdPersonController;
//GameObject thirdPersonInput;
//public GameObject[] RefineryWorker_ChildGameobjects;
// Start is called before the first frame update
void Start()
{
//thirdPersonController = GameObject.Find("PlayerPrefab");
//thirdPersonController.GetComponent<VThirdPersonController>();
//thirdPersonInput = GameObject.Find("PlayerPrefab");
//thirdPersonInput.GetComponent<VThirdPersonInput>();
if(photonView.IsMine)
{
transform.GetComponent<VThirdPersonController>().enabled = true;
transform.GetComponent<VThirdPersonInput>().enabled = true;
PlayerCamera.GetComponent<Camera>().enabled = true;
}
else
{
transform.GetComponent<VThirdPersonController>().enabled = false;
transform.GetComponent<VThirdPersonInput>().enabled = false;
PlayerCamera.GetComponent<Camera>().enabled = false;
}
SetPlayerUI();
}
// Update is called once per frame
void Update()
{
}
void SetPlayerUI()
{
if(playerNameText!=null)
{
playerNameText.text = photonView.Owner.NickName;
}
}
}
I've tried multiple methods to call the other script, but keep getting the "The type or namespace name 'VThirdPersonController' could not be found (are you missing a using directive or an assembly reference?)" error. fully I realise this is probably just a C# issue, but like I said I'm learning and have put in hours trying to find/understand a solution but so far no luck. Can anyone here please help? Thanks in advance :dizzy: