- Home /
Why doesn't an object appear on both screens? (Unity networking)
#pragma strict
import UnityEngine.Networking;
class Queue extends NetworkBehaviour
{
var Car : GameObject;
var queueing : boolean;
var timer : GameObject;
var manager : GameObject;
function Start ()
{
ClientScene.RegisterPrefab(Car);
timer = GameObject.Find("GlobalTimer");
manager = GameObject.Find("NetworkManager");
}
function Update ()
{
if(Input.GetKeyDown(KeyCode.F2))
{
queueing = !queueing;
Debug.Log(queueing);
}
if(queueing == true && timer.GetComponent(RaceTimer).starting == true)
{
CmdSpawn();
}
}
}
function CmdSpawn()
{
var c = Instantiate(Car);
NetworkServer.Spawn(c);
Destroy(gameObject);
}
That's my script but when I spawn the car , it doesn't appear on both screens nor does it think it's a "localplayer"? Any help?
Answer by p1g30n · Apr 16, 2017 at 09:16 PM
I really can't tell what is the problem, because there might be some, but I am sure that video will help you if you do and check every step made in this video. https://www.youtube.com/watch?v=V6wEvT6G92M&t=3275s&list=WL∈dex=33
It's fine, i'll just do it in C# and replicate what I see in the video as networking doesn't seem to work with Java. Thanks
Answer by Delforce · Apr 17, 2017 at 07:32 PM
From what I can tell by the code it seems that possibly your destroying the gameobject of the Car that your wanting on the network. What happens when you don't destroy the gameobject?
I'm not destroying the car. I'm spawning the car on the network while walking around on foot with a spawner script which then destroys the fps character. The car spawns on one but not both screens.
Your answer
![](https://koobas.hobune.stream/wayback/20220612115828im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
Spawn GameObjects before client joins? (Mirror Networking) 0 Answers
Why I cant use 2 NetworkManagers in the same time? 0 Answers
InvalidProgramException: Invalid IL code? Mirror 0 Answers
Multi-threading safely 1 Answer