Individual Flashlights

Not much of a question asker but I am having trouble with my school project.

My game takes place in a very dark area so each player is given flashlights, but my problem is getting one player to see the others flashlight. It always appears that they are walking around in the dark even though their flashlights are on.

Kinda new to networking so I have no idea what could be wrong.

This is a problem I faced. The following script is my now working version.

	public int BatteryLife = 100;
	public float myTimer = 20.0f;
	public Font f;
	public Light playerflash;

	
	void OnNetworkInstantiate(NetworkMessageInfo msg )
	{
		if(!networkView.isMine)
			this.enabled = false;
	}
	
	// Use this for initialization
	void Start () 
	{
	
	}
	
	
	// Update is called once per frame
	void Update () 
	{
		
		if (playerflash.enabled)
		{
		
			if (myTimer > 0) {
			
				myTimer -= Time.deltaTime;
				
			}
			
			if (myTimer <= 0) {
			
				BatteryLife -= 5;
				myTimer = 20.0f;
				
			}
			
		}
	
		if(Input.GetButtonDown("toggleLight")  !playerflash.enabled){
			
		playerflash.enabled = true;
		audio.Play();
	 	
			
		}
		
		else if (Input.GetButtonDown("toggleLight")  playerflash.enabled){
			
		playerflash.enabled = false;
		audio.Play();
			
			
		}
		
	}
	
	void OnSerializeNetworkView(BitStream stream)
	{
		bool isLightOn = playerflash.enabled;	
		stream.Serialize(ref isLightOn);
		
		
		if (stream.isReading)
		{
			playerflash.enabled = isLightOn;
	
		}
	}
	
}

Don’t just copy and paste it. Try and understand it!

I wrote this up just now so it may not work perfectly. You need to assign the light in the insepctor.

var light : Light;
private var lightOn : boolean = false;

function Update () {

	if(networkView.isMine){
	
		if(Input.GetKeyDown(KeyCode.F)){
		
			if(!lightOn){
			
				networkView.RPC("TurnLightOn", RPCMode.All, true); //Turn on
			}
			
			else{
			
				networkView.RPC("TurnLightOn", RPCMode.All, true); //Turn off
			}
			
			lightOn = !lightOn;
		}
	}
}

@RPC
function TurnLightOn (on : boolean) {

	lightOn = on;
	
	if(on){
	
		light.intensity = 1;
	}
	
	else{
	
		light.intensity = 0;
	}
}

It’s giving me an error:
Assets/Resources/OldScripts/Misc/FlashLight.js(63,9): BCE0004: Ambiguous reference ‘light’: FlashLight.light, UnityEngine.Component.light.

Change the variable ‘light’ to ‘flashlight’. Also remember to change it wherever it is referenced.