- Home /
Question by
Vladik1093201 · Jun 21, 2021 at 11:52 AM ·
scripting problemnetworkingmultiplayer
MLAPI Client can't see a gameobject
Hi everyone. Beginner is here. So there's a problem with client. He can't see an object on host's server.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MLAPI;
public class Pickup : NetworkBehaviour
{
[SerializeField] private NetworkObject BottlePrefab;
[ServerRpc]
public void SpawnCubeServerRpc()
{
//Spawn object on a random location
Vector3 position = new Vector3(Random.Range(-30.0f, 30.0f), 19f, Random.Range(-30.0f, 30.0f));
NetworkObject BottleInstance = Instantiate(BottlePrefab, position, Quaternion.identity);
BottleInstance.GetComponent<NetworkObject>().Spawn();
}
//Destroy on collect
public void OnTriggerExit(Collider collider)
{
if (collider.gameObject.name == "Player(Clone)")
{
DestroyBottle();
}
}
//Collect
public void OnTriggerEnter(Collider collider)
{
if (collider.gameObject.name == "Player(Clone)")
{
SpawnCubeServerRpc();
}
}
//Destroy object
public void DestroyBottle()
{
Destroy(gameObject, 0.03f);
}
}
How to make the object sync for the client?
bandicam-2021-06-21-16-23-23-244.jpg
(272.2 kB)
Comment
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
How to check for a host in a certain area in a open world game? 0 Answers
Unet Procedure Calls? 0 Answers
How can I get a variable from another player? 0 Answers
UNet Shooting Projectiles easy method? 0 Answers