Okay so I've pretty much edited the entire question but it's still the exact same question. Currently we have a 4 person multiplayer game that works over a network. We use a particle emitter as a firing mechanism, each player has their own particle emitter but they all use the same "Fire" script.
How do we set the appearance of a players particles over the network. This includes force properties, shaders & textures and even states (eg flamethrower or normal shot) Should I just make 4 scripts one for each fire (which is what we resorted to for the player and everything works perfectly no torubles now) or is there a way to send a player's emitter state via RPC without it taking too much bandwidth sending every single variable?
We have a set up so that player one is the host who launches/runs the server. We have a pickup that activates the FLAMETHROWER and that works fine, locally. Each player can see the pickup and collect the pickup. When the player has collected the pickup it only shows on their machine. Everyone else registers the fact that a certain player has picked it up but still the particles remain the same. What we are looking for is a way to set what the particles are doing locally then send it over the network so that each player can see exactly how far your firing and whether or not your have a flamethrower etc (we also have aiming which increases the particles local velocity which needs to be synced)
This is what we have so far. The part in which we set emitter on and off over the network works fine however the RPC call "SwitchFire" doesn't work at all.Mainly because the variable we are setting doesn't do anything, just demonstrating the fact we have had several attempts (and failed each time, this just causes no problems)
private var wasEmitting : boolean = false;
static var Ammo1 : float = 100;
var AmmoRep : float = 100;
static var AmmoUnlimited : boolean = false;
var AuTime : float = 10;
var Ammo1full : float = 100;
var CanFire : boolean = true;
var SpoutPos : Vector3 = new Vector3(-0.05,0.7,0.45);
static var Aimvar : Vector3 = new Vector3(0,5,5);
var bforce : Vector3 = new Vector3(0,-50,0);
var isFlameThrower : boolean = false;
var wasFlameThrower : boolean = false;
static var FLAMETHROWER : boolean = false;
var flameon : boolean = false;
var hasfilled : boolean = false;
var flamethrowerPos : Vector3 = new Vector3(0,0.35,0.05);
var flameLife : float = 0.5;
var flameAmount : float = 200;
var flameVel : Vector3 = new Vector3(0,0,5);
var flameSize : Vector3 = new Vector3(1,1,1);
var forceOverTime : Vector3 = new Vector3(0,0,0);
var flameSpeed : float = 0.5;
var Fire : Texture;
var Flame : Shader = Shader.Find( "Particles/Additive (Soft)" );
var Tea : Texture;
var regShad : Shader = Shader.Find( "Transparent/Diffuse" );
function Update ()
{
AmmoRep = Ammo1;
if (networkView.isMine)
{
if (FLAMETHROWER == true)
{
flameon = true;
networkView.RPC("SwitchFire", RPCMode.Others, flameon);
QuickFill();
transform.localPosition = flamethrowerPos;
renderer.material.mainTexture = Fire;
renderer.material.shader = Flame;
particleEmitter.minEnergy = flameLife;
particleEmitter.maxEnergy = flameLife;
particleEmitter.minEmission = flameAmount;
particleEmitter.maxEmission = flameAmount;
particleEmitter.localVelocity = flameVel;
particleEmitter.rndVelocity = flameSize;
blah = GetComponent (ParticleAnimator);
blah.force = forceOverTime;
blah.damping = flameSpeed;
if(Input.GetButton("Fire"))
{
particleEmitter.emit = true;
Ammo1 = Ammo1 - 9*Time.deltaTime;
if (Ammo1 <= 0)
{
FLAMETHROWER = false;
hasfilled = false;
CanFire = true;
networkView.RPC("SetIsOut", RPCMode.Others, particleEmitter.emit);
wasEmitting = particleEmitter.emit;
Refill();
}
}
else
{
particleEmitter.emit = false;
}
}
if (FLAMETHROWER == false)
{
flameon = false;
networkView.RPC("SwitchFire", RPCMode.Others, flameon);
hasfilled = false;
transform.localPosition = SpoutPos;
renderer.material.mainTexture = Tea;
renderer.material.shader = regShad;
particleEmitter.minEnergy = 1.5;
particleEmitter.maxEnergy = 1.5;
particleEmitter.minEmission = 25;
particleEmitter.maxEmission = 25;
particleEmitter.localVelocity = Aimvar;
particleEmitter.rndVelocity = Vector3(0.2,0.2,0.04);
blah = GetComponent (ParticleAnimator);
blah.force = bforce;
blah.damping = 10;
if (AmmoUnlimited == true)
{
Refill();
CanFire = true;
UnlimitedAmmoCountDown();
}
if (CanFire == true)
{
if(Input.GetButton("Fire"))
{
particleEmitter.emit = true;
if (AmmoUnlimited == false)
{
Ammo1 = Ammo1 - 9*Time.deltaTime;
}
if (Ammo1 <= 0)
{
CanFire = false;
networkView.RPC("SetIsOut", RPCMode.Others, particleEmitter.emit);
wasEmitting = particleEmitter.emit;
}
}
else
{
particleEmitter.emit = false;
if (Ammo1 <= Ammo1full)
{
Ammo1 = Ammo1 + 11*Time.deltaTime;
}
}
}
}
if (CanFire == false)
{
particleEmitter.emit = false;
Ammo1 = Ammo1 + 8*Time.deltaTime;
if (Ammo1 >= Ammo1full)
{
CanFire = true;
}
}
if(particleEmitter.emit != wasEmitting)
{
networkView.RPC("SetIsFiring", RPCMode.Others, particleEmitter.emit);
wasEmitting = particleEmitter.emit;
}
}
}
function QuickFill()
{
if (hasfilled == false)
{
Ammo1 = 100;
hasfilled = true;
}
}
function Refill()
{
Ammo1 = 100;
Debug.Log ("Refill function activated");
}
function Reloading ()
{
CanFire = false;
if (Ammo1 >= Ammo1full)
{
CanFire = true;
}
}
function UnlimitedAmmoCountDown()
{
yield WaitForSeconds (AuTime);
AmmoUnlimited = false;
}
@RPC
function SetIsFiring(boolEmitting : boolean)
{
particleEmitter.emit = boolEmitting;
}
@RPC
function SetIsOut(boolEmitting : boolean)
{
particleEmitter.emit = false;
}
@RPC
function SwitchFire (flamebool : boolean)
{
flameon = flamebool;
Debug.Log ("recieved fire RPC");
}