- Home /
How to instantiate a projectile only from the weapon prefab of the firing player?
I have a local multiplayer game that features two players that are each equipped with a weapon, which is instantiated as a child for each player upon start. The issue I am having is that currently, whenever I press the "Shoot" button, I get projectiles instantiating from BOTH players weapon; not just the weapon from the firing player.
void Shoot () {
if(Time.time >= nextTimeToFire && standardShot)
{
Instantiate(projectile, nozzle.position, nozzle.rotation, transform);
nextTimeToFire = Time.time + 1 / fireRate;
}
Any ideas on what I can change to the Instantiation script to get it to only fire the projectile from the weapon of the player who shot it?
show the code detect user input and event trigger the Shoot func
User Input if (player.GetButtonDown("Shoot")) { FindObjectOfType().Send$$anonymous$$essage("Shoot"); Debug.Log("Player 1 Shot"); shooting = true; }else { shooting = false; }
Answer by nkcowmaster · Jan 09, 2019 at 05:11 PM
User Input
if (player.GetButtonDown("Shoot"))
{
FindObjectOfType<Weapon>().SendMessage("Shoot");
Debug.Log("Player 1 Shot");
shooting = true;
}else { shooting = false; }