Help Script in photon

Options
I do not quite understand the photon functions wanted to check if it's right my script I want to let him in photon online
using UnityEngine;
using System.Collections;
[RequireComponent(typeof(PhotonView))]
public class carlights : bl_PhotonHelper {

	public Renderer brakelights;
	public Material brakelightON;
	public Material brakelightOFF;

	public Renderer headlights;
	public Material headlightsON;
	public Material headlightsOFF;

	public Renderer turnSignalLEFT;
	public Renderer turnSignalRIGHT;
	public Material turnsignalON;
	public Material turnsignalOFF;

	public Light spotlightLEFT;
	public Light spotlightRIGHT;

	private bool rightSignalON = false;
	private bool leftSignalON = false;
	private PhotonView view = null;

	// Use this for initialization
	void Start () {
	
	}
	
	[PunRPC]// Update is called once per frame
	void Update () 
	{
		//braking//
		if(Input.GetKey(KeyCode.DownArrow))
		{
			brakelights.material = brakelightON;
		}
		//not braking//
		else
		{
			brakelights.material = brakelightOFF;
		}

		//headlights on/off//
		if(Input.GetKeyDown("1"))
		{
			headlights.material = headlightsON;
			spotlightLEFT.intensity = 8f;
			spotlightRIGHT.intensity = 8f;
		}
		if(Input.GetKeyDown("2"))
		{
			headlights.material = headlightsOFF;
			spotlightLEFT.intensity = 0f;
			spotlightRIGHT.intensity = 0f;
		}

		//steer right//
		if(Input.GetKey(KeyCode.RightArrow))
		{
			turnSignalRIGHT.material = turnsignalON;
			turnSignalLEFT.material = turnsignalOFF;
			rightSignalON = true;
			leftSignalON = false;
		}
		else if(Input.GetKey(KeyCode.LeftArrow))
		{
			turnSignalRIGHT.material = turnsignalOFF;
			turnSignalLEFT.material = turnsignalON;
			rightSignalON = false;
			leftSignalON = true;
		}
		else
		{
			turnSignalRIGHT.material = turnsignalOFF;
			turnSignalLEFT.material = turnsignalOFF;
			rightSignalON = false;
			leftSignalON = false;
		}

		if(leftSignalON)
		{
			float floor = 0f;
			float ceiling = 1f;
			float emission = floor + Mathf.PingPong(Time.time*2f, ceiling - floor);
			turnSignalLEFT.material.SetColor("_EmissionColor",new Color(1f,1f,1f)*emission);
		}
		if(rightSignalON)
		{
			float floor = 0f;
			float ceiling = 1f;
			float emission = floor + Mathf.PingPong(Time.time*2f, ceiling - floor);
			turnSignalRIGHT.material.SetColor("_EmissionColor",new Color(1f,1f,1f)*emission);
		}


	}
}

Comments

  • N1warhead
    Options
    Never RPC the Update function, you'll be in a world of hurt if you did.

    What you need to do is, when a button is (Down) not GetKey, but instead use GetKeyDown.
    Inside that do

    if(Input.GetKeyDown(KeyCode.SomeKey)){
    if(photonView.isMine){
    photonView.RPC("MethodName", PhotonTargets.All);
    }
    }

    [PunRPC]
    public void MethodName{
    Debug.Log("WORKED");
    }
  • Erisangt
    Options
    thank you bro helped a lot ;)
  • Erisangt
    Options
    I made the changes but still not working What do I do
    using UnityEngine; using System.Collections; [RequireComponent(typeof(PhotonView))] public class carlights : bl_PhotonHelper { public Renderer brakelights; public Material brakelightON; public Material brakelightOFF; public Renderer headlights; public Material headlightsON; public Material headlightsOFF; public Renderer turnSignalLEFT; public Renderer turnSignalRIGHT; public Material turnsignalON; public Material turnsignalOFF; public Light spotlightLEFT; public Light spotlightRIGHT; private bool rightSignalON = false; private bool leftSignalON = false; private PhotonView view = null; // Use this for initialization void Start () { } [PunRPC] public void MethodName () { //braking// if (Input.GetKeyDown (KeyCode.DownArrow)) { if (photonView.isMine) { photonView.RPC ("MethodName", PhotonTargets.All); } brakelights.material = brakelightON; } //not braking// else { brakelights.material = brakelightOFF; } //headlights on/off// if (Input.GetKeyDown ("1")) { if (photonView.isMine) { photonView.RPC ("MethodName", PhotonTargets.All); } headlights.material = headlightsON; spotlightLEFT.intensity = 8f; spotlightRIGHT.intensity = 8f; } if (Input.GetKeyDown ("2")) { if (photonView.isMine) { photonView.RPC ("MethodName", PhotonTargets.All); { headlights.material = headlightsOFF; spotlightLEFT.intensity = 0f; spotlightRIGHT.intensity = 0f; } //steer right// if (Input.GetKeyDown (KeyCode.RightArrow)) { if (photonView.isMine) { photonView.RPC ("MethodName", PhotonTargets.All); } turnSignalRIGHT.material = turnsignalON; turnSignalLEFT.material = turnsignalOFF; rightSignalON = true; leftSignalON = false; } else if (Input.GetKeyDown(KeyCode.LeftArrow)) { if (photonView.isMine) { photonView.RPC ("MethodName", PhotonTargets.All); } turnSignalRIGHT.material = turnsignalOFF; turnSignalLEFT.material = turnsignalON; rightSignalON = false; leftSignalON = true; } else { turnSignalRIGHT.material = turnsignalOFF; turnSignalLEFT.material = turnsignalOFF; rightSignalON = false; leftSignalON = false; } if (leftSignalON) { float floor = 0f; float ceiling = 1f; float emission = floor + Mathf.PingPong (Time.time * 2f, ceiling - floor); turnSignalLEFT.material.SetColor ("_EmissionColor", new Color (1f, 1f, 1f) * emission); } if (rightSignalON) { float floor = 0f; float ceiling = 1f; float emission = floor + Mathf.PingPong (Time.time * 2f, ceiling - floor); turnSignalRIGHT.material.SetColor ("_EmissionColor", new Color (1f, 1f, 1f) * emission); Debug.Log ("WORKED"); } } } } }
  • jeanfabre
    Options
    Hi,

    You need to do it differently. Synchronize the Inputs, and the scripts responsible for light gets the input value not from Unity Input but from the synchronized value. then you have one script working for all players across the network and you need another script to catch input and write, or read input.

    Check out the Pun basic tutorial. it synchronizes the Health value, in your case it's very much the same, based on a given value, you want to animate things up.

    http://doc.photonengine.com/en-us/pun/current/tutorials/pun-basics-tutorial/player-networking#health
    http://doc.photonengine.com/en-us/pun/current/tutorials/pun-basics-tutorial/player-ui-prefab#bind

    if you follow the same pattern, you'll be fine.

    Bye,

    Jean