- Home /
How to find a game object with networking
I'm just getting started with understanding networking and I'm confused about what I need to do to find a game object active in the scene since I can't get GameObject.Find to return any game objects. I've got a simple Player GameObject that gets spawned for each user that joins, and when they join, I want to find and store reference to an Enemy GameObject that is already active on start.
I've tried GameObject.Find, finding by tag, and type, and including them in a Cmd function to run on the server. There's also the NetworkInstanceId in which I could use something like ClientScene.FindLocalObject(), but I don't know how to get the netId of it without already having a reference to the Enemy Game Object. I've also tried to have the Player spawn with a trigger collider within the collider of the Enemy to see if I can get the reference using OnTriggerEnter, but no success there.
If someone could correct and explain to me what should be done, I'd be very grateful. I'm sure it's likely something really simple that I've just not found asked or in a tutorial yet.
To add on to the above question, I have also tried setting up a spawner script to spawn the enemy using NetworkServer.Spawn() to make sure it's known by the server but that also hasn't worked. The most common way that pretty much every tutorial uses to get a reference to another game object is through using a trigger, yet having the function below on my player doesn't even run when there is a collision.
void OnTriggerEnter(Collider collision) { Debug.Log("A collision occured"); }
$$anonymous$$y only thought on this is that the movement isn't synced properly for the clients and server, but even starting with the colliders within one another, I still haven't got anything.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
[UNET] Only spawn certain server objects on local client? 0 Answers
C# How to have a toggle 1 Answer