Hi, my problem is that when I shoot to a player, unity says that allocated ID 51 doesn’t exist when I call the RPC to kill the player.
I don’t understand. Player’s IDs are 1 and 50.
Sorry for my english.
PS: I’m using MasterServer to make a Lobby and than I load the level
void OnLevelWasLoaded(int level)
{
Debug.Log("level loaded");
Spawn();
Debug.Log("spawning");
}
void Spawn()
{
Network.Instantiate(player, respawnPoint.transform.position, transform.rotation, 0);
}
void Shoot()
{
.....
RaycastHit hit;
Debug.DrawRay(RayStart.transform.position, RayStart.forward * gittata, Color.blue);
if(Physics.Raycast(RayStart.transform.position, RayStart.forward,out hit, gittata))
{
if (hit.rigidbody)
{
hit.rigidbody.AddForceAtPosition(RayStart.forward * forza, hit.point);
}
if(hit.collider)
{
GameObject macchiaInst = Network.Instantiate(macchia, hit.point, Quaternion.FromToRotation(Vector3.up,hit.normal),0) as GameObject;
macchiaInst.transform.parent = hit.transform;
Physics.IgnoreCollision(macchiaInst.collider, macchiaInst.collider);
}
colpito = hit.transform.tag;
if (hit.transform.tag == "Player")
{
punti += 10;
parentOk = null;
Transform app = hit.transform;
while(parentOk==null)
{
if(app.parent.networkView != null)
parentOk = app.parent;
else
app = app.parent;
}
app = transform;
Transform parentMio = null;
while(parentMio==null)
{
if(app.parent.networkView != null)
parentMio = app.parent;
else
app = app.parent;
}
NetworkViewID dati = parentMio.networkView.viewID;
networkView.RPC("ApplicaDanno",parentOk.networkView.viewID.owner,dati);
killer = dati.ToString();
}
...
}
[RPC]
void ApplicaDanno( NetworkViewID nv)
{
killer = nv.owner.ipAddress;
GUI.Label(new Rect(10,210,250,25), nv.owner.ipAddress +" mi ha colpito ed il suo id è: " + nv);
}