- Home /
A question regarding networking...
I have a question regarding the following script:- (FPS Game Script) I want to find an object named player which are many in a multiplayer game. So the question is, If i use networkView.isMine boolean (bool) , the game will find only that player object which is played by one player, and if I want to destroy only the body of the player who dies, only it will be destroyed or others will also be destroyed???
using UnityEngine;
using System.Collections;
public class NetworkingScript : MonoBehaviour
{
void Start ()
{
}
void Update ()
{
if (networkView.isMine)
{
if (GameObject.Find("Player"))
{
Destroy(GameObject.Find("Player"));
Destroy(gameObject);
}
}
}
}
Thanks in advance...
I'm not really sure what you're asking, could you rephrase it?
For example: If three players are playing in a multiplayer game, and all of them have tags named "Player". Let those players have name 'A', 'B' and 'C'.
Now if Player A's Destroy(GameObject.FindGameObjectWithTag("Player")) command is executed using networkView.is$$anonymous$$ine condition, so will it only search and give the reference to it own body or it will return reference for others also???
You should research and understand the philosophy of online games first.
Answer by Lilbob · Mar 14, 2015 at 04:41 PM
You want to use Network.Destroy(NetworkViewID);
The issue with using GameObject.Find("Player") though, is that if your objects are network instantiated, then it will find all players in the scene. Your best bet is using NetworkView.Find(NetworkViewID), OR put a tag on the players, FindObjectsWithTag("Player"), then iterate through them to see which NetworkView is owned by you.
Cheers
Answer by el-pepi · Mar 14, 2015 at 03:46 PM
I belive you are looking for something like this: http://docs.unity3d.com/ScriptReference/Network.Destroy.html
Answer by One Ring · Mar 14, 2015 at 11:29 AM
I don't think that script will have the intended effect, you are checking whether something isMine before you are finding the player, but I'm not positive what you are trying to achieve, if you want to destroy the player controlled by the client that that script is being run on, then find all of the players and for each of them check their isMine, and if its true, then destroy them.
Your answer
Follow this Question
Related Questions
Multiplayer Flashlight Issue 1 Answer
Unity RPC mismatch 0 Answers
How to sync position only one time, using Photon Networking 1 Answer
Overloading RPCs 1 Answer
Networking trouble 1 Answer