lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 13, 2020 21:49:08 GMT
insert code here insert code here 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 instatiate players in a 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! (Thanks Invector, one pro purchase coming up The only thing left to do is to let each player take control of their character when they enter the multplayer 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. This is what I have done based on how I understand it: 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). My errors are for the movement controllers the script cannot reference: Script started out as something like this: using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Photon.Pun;
using TMPro;
public class PlayerSetup : MonoBehaviourPunCallbacks
{
[SerializeField]
TextMeshProUGUI playerNameText;
[SerializeField]
GameObject PlayerCamera;
//public GameObject[] RefineryWorker_ChildGameobjects;
// Start is called before the first frame update
void Start()
{
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;
}
}
} And has now ended up somewhere here: 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();
}
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 :D
|
|
lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 14, 2020 12:35:01 GMT
If it makes a difference I am on the free (LITE) locomotion pack
|
|
|
Post by Chronicman on Mar 14, 2020 15:29:30 GMT
Kind of confused as to what your problem is but looking at your script looks like your missing namespaces.
using Invector; using Invector.vCharacterController; using Invector.vCamera;
your trying to reference a script but it cant find it because of the missing namespace..... I think
On another note: A user has made an addon for pun multiplayer. Its gonna save you a lot of headache considering your new.
|
|
lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 14, 2020 17:13:37 GMT
Thanks for the reply. I got as far as using Invector.vCharacterController; and it sorted out the issue, but I've been having a hard time controlling the characters properly, especially with the camera. When I disable this script it works fine if I test play on my own, but this script is used to gain control when in multiplayer. I tried the additions you mention above but got this error: The type or namespace name 'vCamera' does not exist in the namespace 'Invector' (are you missing an assembly reference?)
What I'm noticing now is that when this script in active, it disables ThirdPersonInput, though not sure why. Also, as my PlayerPrefab is a prefab made up of vThirdPersonCamera_LITE and vBasicController_Character, I assign the vThirdPersonCamera_LITE to the searialized camera. When I load the multiplayer scene (Photon PUN2) my player controls are crap, but when I disable PlayerSetup script, its flawless. Any pointers would be really welcome.
Also, is there a link to this addon?
|
|
lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 14, 2020 17:13:53 GMT
using System.Collections; using System.Collections.Generic; using UnityEngine; using Photon.Pun; using TMPro; using Invector; using Invector.vCharacterController; //using Invector.vCamera;
public class PlayerSetup : MonoBehaviourPunCallbacks { [SerializeField] TextMeshProUGUI playerNameText;
[SerializeField] GameObject PlayerCamera;
vThirdPersonController thirdPersonController; vThirdPersonInput thirdPersonInput; vThirdPersonCamera thirdPersonCamera;
// Start is called before the first frame update void Start() {
thirdPersonController = gameObject.GetComponent<vThirdPersonController>(); thirdPersonInput = gameObject.GetComponent<vThirdPersonInput>(); thirdPersonCamera = gameObject.GetComponent<vThirdPersonCamera>();
if (photonView.IsMine) { transform.GetComponent<vThirdPersonController>().enabled = true; transform.GetComponent<vThirdPersonInput>().enabled = true; PlayerCamera.GetComponent<vThirdPersonCamera>().enabled = true; } else { transform.GetComponent<vThirdPersonController>().enabled = false; transform.GetComponent<vThirdPersonInput>().enabled = false; PlayerCamera.GetComponent<vThirdPersonCamera>().enabled = false; } SetPlayerUI(); }
// Update is called once per frame void Update() { }
void SetPlayerUI() { if(playerNameText!=null) { playerNameText.text = photonView.Owner.NickName; } }
}
|
|
|
Post by Chronicman on Mar 14, 2020 19:10:26 GMT
This is pretty advanced stuff for a new user btw lol. if (photonView.IsMine) is asking if the character is the users character is the one true character if so enable the components, else if is not meaning he is remote then turn it off. You do this so you don't control all the characters in scene at once. What you wrote there should not really effect your characters control that I know about. You should really go check out the addons section. For 18$ usd all this stuff is done for you. As a new user you should really be using it, until you lean more then you could tackle these small problem easy.
|
|
lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 15, 2020 15:22:24 GMT
Thanks, I've purchased the addon and the melee combat premium pack. So far so good, just stuck at testing phase.
I'm stuck at the point where I pass all final tests and try launch into the game to run around the scene and check everything works. When I hit play I get 2 "NullReferenceException: Object reference not set to an instance of an object" errors and 2 "SerializedObjectNotCreatableException: Object at index 0 is null" errors. Not sure why and can't find much in terms of solutions (yet) online. Was wondering if anyone else had this issue and how they solved it? Also, I could not interact with my UI and enter my name or proceed past the menu while running the test. I've been following the YouTube tutorial video and got to 10:24 with an all clear in the console when running tests.
|
|
lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 15, 2020 15:36:28 GMT
Just figured it out; my GameController, UI and Event System were a child of my player prefab. Unpacked and reorganised and was able to play. Errors (red) were still in my console but I could play. Should still get those fixed though.
|
|
|
Post by Chronicman on Mar 15, 2020 16:18:11 GMT
If your having trouble setting it up and getting every thing to work properly, post it in the multiplayer addon post for support. =) The dev did a really good job with that addon from what I'm told.
|
|
lokimotiveuk
New vMember
Loving this platform, learning as fast as I can :D
Posts: 7
|
Post by lokimotiveuk on Mar 15, 2020 18:18:50 GMT
Thanks, I will. Having a few issues but will take it up there. Thanks for all your help!!
|
|