Question by
neonstarfruit · Mar 09, 2018 at 03:10 AM ·
c#networkingclient-serverclientsauthoritative server
UNet Sharing Gameobjects between multiple clients
I am fairly new at Unity but currently I am working on a mining game where all the players need to be able to remove all the objects. Currently I have it set so it runs through a [Command] to see if the client is clicking on the object, and if it is, destroy it.
void Start()
{
if (Input.GetButton("Fire1")) //If player is attacking call broken function
{
CmdBroken();
}
}
[Command]
void CmdBroken()
{
if (Physics.Raycast(cam.transform.position, cam.transform.forward, out _hit, (float)range * 5,
maskRay)) //If camera is looking at an ore break it
{
_pos = _hit.transform.position;
if (_hit.collider.tag == "Dirt")
{
if (timeToBreak <= 1)
{
breakCountDown = ((float)2) / (float)Damage; //break Dirt/Add dirt to inventory/ call block spawning function
timeToBreak = Time.time + breakCountDown;
}
if (Time.time >= timeToBreak || timeToBreak <= 1)
{
Dirt += 1;
timeToBreak = 0f;
Debug.Log(_pos);
NetworkServer.Destroy(_hit.transform.gameObject);
}
}
}
}
Comment
Your answer
Follow this Question
Related Questions
Spawning Network Objects from the client | Unity Netcode For Gameobjects 0 Answers
non-player object can't execute's "[Command]"'s attributes 0 Answers
[UNET] How do I allow clients to move a GameObject that exists on the server? 0 Answers
Calling Bool in Network Command Not Working 0 Answers
SyncVar works not always 0 Answers