Hi,
I’m sure this must have been asked previously…
I’m currently trying to apply force to a Rigidbody component of a prefab thats getting spawned via Network.Spawn however it doesnt appear to be working.
My Prefab has a Network Identity and Network Transform components. I have tried setting the Network Transform Sync mode to Sync Rigidbody 3D
and registerd the component via the NetworkManager SpawnInfo editor UI component
On my player I have a script which notifies the server to spawn my prefab if the player clicks the mouse button as per the code below.
Am I missing something?
TIA,
Lee
void Update ()
{
CheckIsAttacking();
}
private void CheckIsAttacking()
{
if (!isLocalPlayer)
return;
if(Input.GetKeyUp(KeyCode.Mouse0))
{
SpawnPrefab();
}
}
private void SpawnPrefab()
{
CmdSpawnPrefab();
}
[Command]
private void CmdSpawnPrefab()
{
GameObject spawnObj = (GameObject)Instantiate(spawnPrefab, transform.TransformPoint(0, 0, 0.5f), Quaternion.identity);
spawnObj.GetComponent<Rigidbody>().AddForce(transform.forward * 500f);
NetworkServer.Spawn(spawnObj);
}