- Home /
error CS1502 and CS1503
I'm trying to make the character prefab disappear when he/she is disconnecting but I'm getting these errors:
Assets/_Resources/_Scripts/Spawning.cs(22,25): error CS1502: The best overloaded method match for
UnityEngine.Network.RemoveRPCs(UnityEngine.NetworkPlayer)' has some invalid arguments 2. Assets/_Resources/_Scripts/Spawning.cs(22,25): error CS1503: Argument
#1' cannot convertUnityEngine.GameObject' expression to type
UnityEngine.NetworkPlayer'Assets/_Resources/_Scripts/Spawning.cs(23,25): error CS1502: The best overloaded method match for
UnityEngine.Network.DestroyPlayerObjects(UnityEngine.NetworkPlayer)' has some invalid arguments 4. Assets/_Resources/_Scripts/Spawning.cs(23,25): error CS1503: Argument
#1' cannot convertUnityEngine.GameObject' expression to type
UnityEngine.NetworkPlayer'
Here's my code: using UnityEngine; using System.Collections;
public class Spawning : MonoBehaviour { public GameObject Controller;
void OnGUI()
{
if(GUILayout.Button("Spawn"))
{
Network.Instantiate(Controller, transform.position, transform.rotation, 0);
this.enabled = false;
gameObject.GetComponent().enabled = false;
gameObject.GetComponent().enabled = false;
}
}
void OnPlayerDisconnected(NetworkPlayer id)
{
Debug.Log("Clean up after player " + Controller);
Network.RemoveRPCs(Controller);
Network.DestroyPlayerObjects(Controller);
}
}
What am I doing wrong?
Answer by Dave-Carlile · Feb 14, 2013 at 12:56 PM
If you look up each of those methods in the documentation, it will show what data types are required for each parameter. I'll go through Network.RemoveRPCs
There are serveral ways to call this function. There are two that take a single parameter. The data type for the parameter must be either NetworkPlayer
or NetworkViewID
. You're passing in a GameObject
.