guys i am trying to make a multiplayer game but i have a problem that i cant figure out. So the problem is that when the host starts the game every player is moved to the scene named "Game". The characters positions are set to 2 spawnpoints. First one for the host(first person to join the lobby) and the second one for the client(second person to join the lobby) the host spawns at the right spot and everything is OK with him. But the client character spawns at 0, 0.8, 0. And yes the spawn point for the client is set to a different position than 0, 0.8, 0 and the coordinates are 17, 0.8, 0. So can someone help me out?
BTW the player prefabs are already instantiated.
I dont even remember what i have tried anymore.
I'm setting the position inside the main script.
My main script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using Mirror;
public class PlayerMovementController : NetworkBehaviour
{
public float Speed = 0.1f;
public GameObject PlayerModel;
private CustomNetworkManager manager;
private CustomNetworkManager Manager
{
get
{
if (manager != null)
{
return manager;
}
return manager = CustomNetworkManager.singleton as CustomNetworkManager;
}
}
private int i = 0;
private void Start()
{
PlayerModel.SetActive(false);
}
private void Update()
{
if(SceneManager.GetActiveScene().name == "Game")
{
if (PlayerModel.activeSelf == false)
{
SetPosition();
}
if(isOwned)
{
Movement();
}
}
}
public void Movement()
{
float xDirection = Input.GetAxis("Horizontal");
float zDirection = Input.GetAxis("Vertical");
Vector3 moveDirection = new Vector3(xDirection, 0 ,zDirection);
transform.position += moveDirection * Speed * Time.deltaTime;
}
public void SetPosition()
{
Debug.LogWarning(i);
if (i < Spawns.spawnTransforms.Count)
{
Transform spawnPoint = Spawns.spawnTransforms[i];
Debug.LogWarning("SpawnPoint: " + spawnPoint.position);
i++;
Debug.LogWarning(i);
transform.localPosition = new Vector3(spawnPoint.position.x, 0.8f, spawnPoint.position.z);
Debug.LogWarning(transform.position);
PlayerModel.SetActive(true);
Debug.LogWarning("Set Position");
}
else
{
Debug.LogWarning("Not enough spawn points for all players.");
}
}
}
My Spawns script
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Spawns : MonoBehaviour
{
// This is your static list
public static List<Transform> spawnTransforms = new List<Transform>();
// This property exposes the static list for serialization
[SerializeField]
private List<Transform> serializedSpawnTransforms;
private void Awake()
{
// Assign the static list to the serialized property
spawnTransforms = serializedSpawnTransforms;
}
}