Question by
tycrane2 · May 04, 2016 at 04:13 AM ·
networkprojectilenetwork.instantiate
Issue with clone not firing projectile after short time after spawn
Below is a projectile script I use, it works with the original prefab. However, when I connect to my network and spawn the same character it will work for about 5 seconds. Then, the projectile is spawned but nolonger has force behind it. It just spawns under the cloned player. If I enable the original and fire, they both fire. Yes, even the clone is able to fire correctly if the original is enabled in the scene. I don't understand.
GameObject bullet;
public static float bulletSpeed = 75.0f;
public static int ammo = 100;
public Text playerAmmoUi;
// Use this for initialization
void Start()
{
bullet = Resources.Load("Bullet") as GameObject;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.F) && ammo > 0)
{
GameObject Bullet = Instantiate(bullet) as GameObject;
Bullet.transform.position = transform.position;
Rigidbody rb = Bullet.GetComponent<Rigidbody>();
rb.velocity = transform.forward * bulletSpeed;
GameObject.Destroy(Bullet, 3f);
// ammo--;
}
// playerAmmoUi.text = "Ammo: " + ammo.ToString();
}
Comment
Your answer
Follow this Question
Related Questions
Network instantiate 0 Answers
Network Instantiation works on one command and does not work on another 0 Answers
Simple NetworkView Question. 1 Answer
Spawn with local authority 0 Answers