- Home /
Netcode [Command] Issues .. no errors, just not working.
So I have my controller on my Player.prefab that handles input:
//Fire Active Weapon
if (Input.GetMouseButton(0) && GetComponentInChildren<Rifle>())
{
GetComponentInChildren<Rifle>().CmdFire();
}
and inside my Rifle.cs attached to the weapon prefab (child of Player.prefab) looks like this:
[Command]
public void CmdFire()
{
Debug.Log("Fire");
Vector3 randomVec = new Vector3(Random.Range(-timeHeld, timeHeld), Random.Range(-timeHeld, timeHeld), 0f);
GameObject bul = Instantiate(Bullet, bulletSpawn.position, bulletSpawn.rotation) as GameObject;
bul.transform.Rotate(randomVec);
bul.GetComponent<Rigidbody>().velocity = bul.transform.forward * 1000;
NetworkServer.Spawn(bul);
}
When I run both client and host standalone instances of my game, CmdFire() is never getting called on either. Not getting any runtime errors, just zero response to my mouse clicks.
Is there something preventing my Player from telling the Rifle to fire?
Since my Rifle is a child of my Player.prefab, does it need special Network components or settings?
Answer by NFMynster · Aug 25, 2016 at 04:55 PM
Have you registered the bullet prefab in the spawnable prefabs in the network manager?
Your answer
Follow this Question
Related Questions
Unity networking tutorial? 6 Answers
UNET Players not spawning on server change scene 1 Answer
Networking Sync SetActive Not Working 0 Answers
Animating online users sprite 0 Answers
Remote database for leaderboard 2 Answers