Voici le code pour le prefab de la ferme (Resources.cs)
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class Resource : MonoBehaviour {
public enum TypeResource { House,Ferme,Fer,Roche }
public TypeResource Type;
public GameObject InfoGame;
PhotonView view;
public GameObject CameraSelection;
//bonus resource
public int Bonus;
public float Delay;
private float Next;
private float ActuTime;
bool Add ;
void Start () {
InfoGame = GameObject.Find("InfoGame");
Add=true;
view = PhotonView.Get (this);
if (gameObject.tag == "Invite") {
CameraSelection = GameObject.Find ("CameraB");
}
if (gameObject.tag == "Master") {
CameraSelection = GameObject.Find ("CameraA");
}
}
// Update is called once per frame
void Update () {
if (TypeResource.House == Type) {
if (Add == true) {
InfoGame.SendMessage ("AddHouse", Bonus);
Add = false;
}
} else {
ActuTime = Time.time;
}
if (TypeResource.Ferme == Type) {
if (ActuTime > Next + Delay) {
view.RPC ("Addferme", PhotonTargets.All,3);
//InfoGame.SendMessage ("AddFerme", Bonus);
Next = ActuTime;
}
}
if (TypeResource.Fer == Type) {
if (ActuTime > Next + Delay) {
InfoGame.SendMessage ("AddFer", Bonus);
Next = ActuTime;
}
}
if (TypeResource.Roche == Type) {
if (ActuTime > Next + Delay) {
InfoGame.SendMessage ("AddRoche", Bonus);
Next = ActuTime;
}
}
}
}
Code : Tout sélectionner
using UnityEngine;
using System.Collections;
public class CameraR : MonoBehaviour {
public int Bles;
PhotonView view;
// Use this for initialization
void Start () {
view = GetComponent<PhotonView> ();
Debug.Log (view.viewID);
}
// Update is called once per frame
void Update () {
}
[PunRPC]
void Addferme(int bonus)
{
Bles+= 2;
}
}